Hi guys,
I'm trying to use the MatrixMath library (http://playground.arduino.cc/Code/MatrixMath) to solve 3 unknowns with 3 equations. Each equation is a quadratic equation and I'm trying to find the coefficients of the resulting quadratic function as abc[3][1] as follows:
/*
y = ax^2 + bx + c
x1^2, x1, 1
X[3,3] = x2^2, x2, 1
x3^2, x3, 1
y1
Y[3,1] = y2
y3
a
[ b ] = X^(-1) * Y
c
*/
float X[3][3];
X[0][0] = settings.adc_low_cal * settings.adc_low_cal;
X[0][1] = settings.adc_low_cal;
X[0][2] = 1;
X[1][0] = settings.adc_mid_cal * settings.adc_mid_cal;
X[1][1] = settings.adc_mid_cal;
X[1][2] = 1;
X[2][0] = settings.adc_high_cal * settings.adc_high_cal;
X[2][1] = settings.adc_high_cal;
X[2][2] = 1;
float Y[3][1] = {settings.temp_low_cal, settings.temp_mid_cal, settings.temp_high_cal};
//abc[3][1] is global
Matrix.Invert((float*)X,3); //must be called separately. This function replaces the matrix X with it's inversion.
Matrix.Multiply((float*)X, (float*)Y, 3, 3, 1, (float*)abc); //use matrix math library to get a, b and c of y = ax^2 + bx + c
I've modeled the scenario in Matlab and it shows me that the variable "a" is often of the order of e^-5 decimal places. The arduino c++ is showing "a" as -0.00. Is there some way to get a with the proper number of decimal places and showing that small of a number?
Thanks for your input...