MatrixMath numbers smaller than e^-5 PROBLEM

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...

You probably need to specify that more decimal places should be printed:

Serial.println(a,8);

Pete

Ah, of course. Too many beers and a long work day make for bad programming. It works fine now. Thanks for the knock upside the head. :sleeping:

Confusion is when we need a knock in the head but can't remember where it is, Or how to get it... or is that old age..?

I can't remember. :slight_smile:

you could update your core print.cpp library with code discussed in this thread - Proposed update for the printFloat code of print.cpp - #11 by robtillaart - Libraries - Arduino Forum - so you can print floats in scientific notation.

The zip file attached to message 10 works quite well for some time now (do not forget to backup the original print.cpp :wink: