From 9c39dce0570d10eaa9fb026a621c8a663c511848 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 11 Feb 2022 20:21:05 -0600 Subject: Use order 1 regression to prevent overfitting --- Detector-Building.ino | 10 +++++----- 1 file 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); -- cgit v1.2.3-70-g09d2