aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-02-11 20:21:05 -0600
committerAnthony Wang2022-02-11 20:21:05 -0600
commit9c39dce0570d10eaa9fb026a621c8a663c511848 (patch)
treed0880787cc3dcc3f6f4c187b4b3871912b184248
parente504cfa397b2aee9895c2abfa1ff9b513909a4f4 (diff)
Use order 1 regression to prevent overfitting
-rw-r--r--Detector-Building.ino10
1 files changed, 5 insertions, 5 deletions
diff --git a/Detector-Building.ino b/Detector-Building.ino
index 498a114..b2c49d3 100644
--- a/Detector-Building.ino
+++ b/Detector-Building.ino
@@ -28,10 +28,9 @@ int d2a(double d) { return d * analog_max / V_in; }
// Voltage to resistance conversion
double v2r(double V_out) { return R_k * (V_in / V_out - 1); }
-double vol[100];
-int con[100];
+double vol[100], con[100];
-const int order = 2;
+const int order = 1;
double coeff[order + 1];
void setup() {
@@ -53,13 +52,14 @@ void setup() {
++n;
}
- fitCurve(order, n, vol, con, coeff);
+ fitCurve(order, n, vol, con, order + 1, coeff);
+ for (int i = 0; i <= order; ++i) Serial.println(coeff[i]);
}
void loop() {
double v = a2d(analogRead(THERM));
double c = 0;
- for (int i = order; i >= 0; --i) c = v*c + coeff[i];
+ for (int i = 0; i <= order; --i) c = v*c + coeff[i];
Serial.print("Voltage: ");
Serial.println(v);