diff options
author | Anthony Wang | 2022-02-11 15:25:23 -0600 |
---|---|---|
committer | Anthony Wang | 2022-02-11 15:25:23 -0600 |
commit | 484a9fcbdb1e545be8395c70deed57c175ba804a (patch) | |
tree | ecba57f8380648e1d522e9f8cf21646fece05ef3 /libraries/CurveFitting/examples/fitCurve/fitCurve.ino | |
parent | 0f1a894cfb90257f767a76417072243be8c20243 (diff) |
Add all Arduino libraries
Diffstat (limited to 'libraries/CurveFitting/examples/fitCurve/fitCurve.ino')
-rw-r--r-- | libraries/CurveFitting/examples/fitCurve/fitCurve.ino | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libraries/CurveFitting/examples/fitCurve/fitCurve.ino b/libraries/CurveFitting/examples/fitCurve/fitCurve.ino new file mode 100644 index 0000000..cbc8966 --- /dev/null +++ b/libraries/CurveFitting/examples/fitCurve/fitCurve.ino @@ -0,0 +1,37 @@ +#include <curveFitting.h> + +void setup(){ + Serial.begin(9600); + while(!Serial); + Serial.println("Starting"); + + char buf[100]; + int xpower = 3; + int order = 3; + snprintf(buf, 100, "Fitting curve of order %i to data of power %i...\n", order, xpower); + Serial.print(buf); + + double x[26]; + double t[26]; + for (int i = 0; i < sizeof(x)/sizeof(double); i++){ + t[i] = i; + x[i] = pow(i, xpower); + } + + double coeffs[order+1]; + int ret = fitCurve(order, sizeof(x)/sizeof(double), t, x, sizeof(coeffs)/sizeof(double), coeffs); + + if (ret == 0){ //Returned value is 0 if no error + uint8_t c = 'a'; + Serial.println("Coefficients are"); + for (int i = 0; i < sizeof(coeffs)/sizeof(double); i++){ + snprintf(buf, 100, "%c=",c++); + Serial.print(buf); + Serial.print(coeffs[i]); + Serial.print('\t'); + } + } +} + +void loop(){ +} |