Page 1 of 1

Help with power function in a Maths Expression

PostPosted: Tue Oct 22, 2013 9:05 pm
by moc
I'm trying to create a Math channel in I2 PRO that will display a boost value taking the altitude into consideration.

The formula for this is:

boost = manifold pressure - atmospheric pressure

To estimate atmospheric pressure at a given altitude you can use this formula:
(kPa at sea level * e ^ -(altitude/7000)*100)

which at Wakefield would be:
(1.01 * 2.7182818285 ^ -(661/7000)*100) = 91.925 kPa

So I attemted to create a Maths channel in I2 PRO like this:
power(1.01*2.7182818285,-1*('GPS Altitude' [m])/7000)*100

and it tells me that the expression is invalid. So I attempted this:
power(1.01*2.7182818285,-661/7000)*100

which I2 will happily resolve to the wrong value. Assuming there was a problem with negative exponents with the power function I tried to create a simple unitless expression to 4 decimal places like this:
power(10,-2)

The result I get is 0 not 0.01. So getting desperate I tried:
1/power(10,2)

and I still got 0 as the result. Getting even more desperate I tried:
1/10/10

and I still got 0 as a result.

Does anyone know what is going on here? There must be some sort of rounding issue I'm not seeing as I2 thinks 3/2 = 1.0000

Re: Help with power function in a Maths Expression

PostPosted: Thu Nov 21, 2013 10:41 am
by MattW
Hi moc,

Don't know why this wasn't answered sooner, so sorry for the delay.

There a a few issues here, some in the logic and some the way i2 does it's integer maths.
The problem is if you feed it all integers it's result will be an integer.
The simple solutions to put .0
e.g
power(10,-2) gives the result 0.00
power(10,-2.0) gives the result 0.02
2/3 gives the result 0.00 (Integer maths always rounds down, even from .99)
2/3.0 gives the result 0.67

So this fix, combined with re-ordering your maths a little (brackets, then power, then multiplication) and we get the correct result.

1.01*power(2.7182818285,-(661.0/7000))*100

Re: Help with power function in a Maths Expression

PostPosted: Thu Nov 21, 2013 11:56 pm
by moc
Thanks Matt,

That explains a few things and I can now get this to work: 1.01*power(2.7182818285,-(661/7000.0))*100

However this: 1.01*power(2.7182818285,-('GPS Altitude' [m]/7000.0))*100 gives me an expression invalid error.

Can you please point me in the right direction again?

Regards,

Mark