 # Translating math equation into code

I am having a bit of trouble with inserting this math equation into code that runs my aquarium's temperature clock.
Here is the equation:

y = -2.889464633·10-16 x7 + 1.281707352·10-12 x6 - 2.403703125·10-9 x5 + 2.469756623·10-6 x4 - 1.500907849·10-3 x3 + 5.393125117·10-1 x2 - 105.9879341 x + 8790.689453

(note this is the exact regression equation. I round the decimals to the 3 decimal points in my code)

This is the code I used (V is the voltage read by the themistor) :

T = (-2.889 * pow(10, -16)) * pow(V, 7) + ( 1.282 * pow(10, -12)) * pow(V, 6) - ...

When I compile and run, the data I get is severely truncated. Is there a better way to write this polynomial?

Your help is very much appreciated.

Moved your topic to it's current location as it is more suitable.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.

You never need to express the powers of ten mantissa this way:

-2.889 * pow(10, -16))

when you are expressing

-2.889464633·10-16

C wants you to say:

-2.889464633E-16

https://www.arduino.cc/reference/en/language/variables/constants/floatingpointconstants/

Also, don’t use expressions like pow(V,7). Instead use the Horner form to evaluate a polynomial (look it up). It is much faster and more accurate.

Example y=ax3+bx2+cx+d is written

y = d + (c + (b + a*x)*x)*x;

the data I get is severely truncated.

How can you tell? Are you just looking at it with Serial.print(), which by default only prints 2 places past the decimal point?

I wont attempt to address your math problem its beyond me but if you want to serial print to greater decimal places use

``````Serial.print(myvalue, 4);
``````

This will print to 4 decimal places