How to use ln(x) in arduino

Hello everyone, I have a question about programming in arduino. I don't know how to use ln(x) in arduino , I need the next function will be working.Help me please

Temperatura = 1 / 4.726504594 * pow(10, -3) - 4.012576310 * pow(10, -4) * ln(Resistencia) + 30.04841481 * pow(10, -7) * ln(pow(Resistencia, 3));

The function calls are log() (base e) and log10() (base 10). You might need to

#include <math.h>

Please use code tags when posting code.

4.726504594*pow(10,-3)*

See how the asterisks got eaten unless you use code tags?

So I was going to write that you can use

4.726504594e-3

as a constant. That’s 0.004726… google

 arduino scientific notation

Know also that Arduino floating point is limited to 6-7 digits, even if you try using double.

a7

You need to look carefully at your equations and the limitations of the maths .
You have some very long numbers there, which are maybe quite meaningless in terms of their effect on any output .

Do some sensitivity checks - reduce the number of places in the numbers , remove some parts of the equation and see the effect in the output over a range of temperatures .
There maybe a better way to get your readings - simple curve fit over a limited range , look up table etc .

Look at the tolerances of the sensor too - that might not be as good as the maths

Depending on what you are doing there maybe a better easier sensor/transducer to use .

  Temperatura = 1 / 4.726504594e-3 
     - 4.012576310e-4 * log(Resistencia) 
    + 30.04841481e-7 * log(pow(Resistencia,3));

can be simplified as

+30.04841e-7 * 3 * log(Resistencia)

(ln :arrow_right:log, supress redundant decimals)

Or, if you prefer

90.14524e-7 * log(Resistencia)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.