 # math formula Programming Help

Hello ,

i'm trying to write a math operation but this don't work

Her is the formula : 7.93-5*log(10^(4.316-(x/5))+1)

i write it like this : 7.93-(5 * log(pow(10, (4.316-(x/5))+1)));

but this solution return me bad result.

Can you help me please ?

François

``````7.93-(5.0 * log(pow(10.0, (4.316-(x/5.0))+1.0)));
``````

but this solution return me bad result.

for example , if x = 21 the good result is 6.11

the arduino formula return me -7.22

With your formula , it returm -4.92

Maybe your parentheses are in the wrong place.

When you want the log, do you want the natural logrithm (written as ln in math but written as log in program) or the base 10 logarithm (written as log in math but written log10 in program)

I was about to assume you must mean natural log since it makes very little sense to take the base 10 logarithm of 10 raised to some power, but I realize that most people don't study math much and might not know that. And if it was written like that in some text it almost assuredly means log base 10.

ie. log(10^x) == x. log and 10^ are inverse operations. It's like having (5 * x) / x. They undo each other.

``````7.93 - (5 * log10(pow(10, 4.316 - x/5.0) + 1))
``````

oqibidipo: ``` 7.93 - (5 * log10(pow(10, 4.316 - x/5.0) + 1)) ```

Or do the obvious elimination there and use

``````7.93 - (5 * (4.316 - x/5.0))
``````

Where did you get this formula? Then we can check you have the right one and how important accuracy is.

Delta_G:
Or do the obvious elimination there and use

``````7.93 - (5 * (4.316 - x/5.0))
``````

`log10(pow(10,...) + 1)` does not cancel.

do the obvious elimination

log10(y + 1) does not equal log10(y).

Ah, sky quality meter equation - Google found it!

jremington: log10(y + 1) does not equal log10(y).

You're right. I had the parenthesis confused. I thought the +1 was inside the exponent part.

Delta_G: You're right. I had the parenthesis confused. I thought the +1 was inside the exponent part.