 # Exponent in Equation, Help!

Hi! Total noob to programming here. I am trying to solve this problem and I am stuck on a line of code. I will bold this line so it can be seen more easily. It is the exponent at the end that I believe is the problem. I am getting the error message: expected ')' before ';' token

The calibration formula for a particular thermistor is  T= 1 / a1 + a2LogRt + a3(LogRt)^3

where Rt is the resistance of the thermistor in ohm, and the calibration constants are a1 = 1.009250 x 10–3, a2 = 2.378405 x 10–4 and a3 = 2.019203 x 10–7. The log(x) function returns the natural logarithm of x. Write the Arduino code to evaluate T for Rt = 15 kΩ. What is T for Rt = 15 kΩ. Your solution should involve definitions for the variables, a1, a2, a3, Rt and T. In other words, define Arduino variables for all symbols that appear in the equation for T, and then use those variables to write an Arduino expression for T.

Here is my code:

void setup() {

Serial.begin(9600); //data rate 9600 bps

Serial.println("Thermistor Temperature Measurement"); Serial.println("\n Vo Rt T"); }

void loop() { int ThermistorPin = 1; int Vo; float logRt,Rt,T; float a1 = 1.009250e-03, a2 = 2.378405e-04, a3 = 2.019203e-07;

Vo = analogRead(ThermistorPin); Rt = 15000;

T = ( 1/( a1 + a2*log10(Rt) + a3*pow(log10(Rt),3) );

Serial.print(" "); Serial.print(Vo); Serial.print(" "); Serial.print(Rt); Serial.print(" "); Serial.println(T); delay(200);

}

Would appreciate any help. Thank you!

``````T = ( 1/( a1 + a2*log10(Rt) + a3*pow(log10(Rt),3) );
``````

Carefully count the opening and closing parenthesis in that statement.

You seem to be asking how to calculate n to the third, right? While pow() can work, it is a wasteful function for calculating n * n * n.

I’m trying to cube a3(LogRt). I was told by a tutor to write a3(LogRt)^3 but I don’t believe that is correct…

emily25:
I’m trying to cube a3(LogRt). I was told by a tutor to write a3(LogRt)^3 but I don’t believe that is correct…

You are correct to think you were told incorrectly. ^ is the XOR operator. You almost have it written correctly. Like I said, count the opening and closing parenthesis in that statement very carefully.

I think I got it! Thank you!!!

T = ( 1/(a1 + a2*log10(Rt) ) + a3*pow(log10(Rt),3) );

It compiled!

It may have compiled but the equation you originally gave:

``````T= 1 / a1 + a2LogRt + a3(LogRt)^3
``````

and what you have in your code:

``````T = ( 1/(a1 + a2*log10(Rt) ) + a3*pow(log10(Rt),3) );
``````

aren't calculating the same thing.

In the first one you have 1/a1 but in the second you have 1/(a1 + a2*log10(Rt)). Not the same thing at all.

Pete

emily25: T = ( 1/(a1 + a2*log10(Rt) ) + a3*pow(log10(Rt),3) );

It compiled!

What happens if you let the compiler know to do everything in floating point arithmetic by adding decimal places?

`````` T = ( 1.0 /( a1 + a2*log10(Rt) + a3*pow(log10(Rt), 3.0) ));
``````

econjack:
What happens if you let the compiler know to do everything in floating point arithmetic by adding decimal places?

Your compiler will be doing everthing in floating point anyway. Values in aritmetic expressions get “promoted” to double if either operand is a double. So the division will be an fp division. The only time you have to watch out is when doing things like

a = 1/3 + log(3);

The 1/3 will be an integer division because both operands are integer. The addition will be fp, but it’s already too late.

Having said that: yeah, using FP constants throughout if you want FP is probably good practise.