Go Down

Topic: windchill formula uses exponents, how do we do that? (Read 1 time) previous topic - next topic

grendle

the windchill formula uses exponents

Code: [Select]

Windchill  = 35.74 + 0.6215*T - 35.75(V^0.16) + 0.4275*T(V^0.16);


where T is temperature
V is wind speed
^0.16 is an exponent.
this is the layout from the nws site but ofcourse the ^0.16 is giving errors on compile, can someone help me please?

JarkkoL


grendle

#2
Jun 30, 2013, 10:40 pm Last Edit: Jun 30, 2013, 10:51 pm by grendle Reason: 1
most awesome of you. thank you  very much JarkkoL.  

for reference, works fine tested with nws windchill calculator
the 2 float values temperature and windspeed are just test numbers, i dont have an anemometer? yet.

Code: [Select]

void setup(){
Serial.begin(9600);
float T=49;
float V=10;

float Windchill  = 35.74 + 0.6215*T - 35.75*pow(V,0.16) + 0.4275*T*pow(V,0.16);
Serial.print(Windchill);

}

void loop(){}

Henry_Best


the windchill formula uses exponents

Code: [Select]

Windchill  = 35.74 + 0.6215*T - 35.75(V^0.16) + 0.4275*T(V^0.16);


where T is temperature
V is wind speed
^0.16 is an exponent.
this is the layout from the nws site but ofcourse the ^0.16 is giving errors on compile, can someone help me please?


As 35.74 and 35.75 are very nearly equal, this formula could be rewritten as
Windchill  = 35.74(1 - (V^0.16)) + T((0.4275(V^0.16)) + 0.6215) with very little error.

grendle



the windchill formula uses exponents

Code: [Select]

Windchill  = 35.74 + 0.6215*T - 35.75(V^0.16) + 0.4275*T(V^0.16);


where T is temperature
V is wind speed
^0.16 is an exponent.
this is the layout from the nws site but ofcourse the ^0.16 is giving errors on compile, can someone help me please?


As 35.74 and 35.75 are very nearly equal, this formula could be rewritten as
Windchill  = 35.74(1 - (V^0.16)) + T((0.4275(V^0.16)) + 0.6215) with very little error.



much appreciated henry, thank you kindly. i will certainly experiment with this info  XD

robtillaart

#5
Jul 01, 2013, 09:47 pm Last Edit: Jul 02, 2013, 07:00 pm by robtillaart Reason: 1
Ans as V^0.16 is used twice one could store it in a variable so it can be reused iso recalculated.

this prints a lookup table for diff values of T and V
Code: [Select]

void setup()
{
 Serial.begin(115200);

 for (int T = 0; T < 100; T++)
 {
   for (int V = 0; V < 15; V++)
   {
     float tt = pow(V, 0.16);
     float Windchill  = 35.74 + 0.6215*T - 35.75*tt + 0.4275*T*tt;
     Serial.print(Windchill);
     Serial.print("\t");
   }
   Serial.println();
 }
}

void loop()
{
}

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

grendle


Ans as V^0.16 is used twice one could store it in a variable so it can be reused iso recalculated.

this prints a lookup table for diff values of T and V
Code: [Select]

void setup()
{
  Serial.begin(115200);

  for (int T = 0; T < 100; T++)
  {
    for (int V = 0; V < 15; V++)
    {
      float tt = pow(V, 0.16);
      float Windchill  = 35.74 + 0.6215*T - 35.75*tt + 0.4275*T*tt;
      Serial.print(Windchill);
      Serial.print("\t");
    }
    Serial.println();
  }
}

void loop()
{
}




very nice Rob, im gonna have to start paying you lol thats twice you rescued me from math  :D. this is sweet and this is the format im gonna use. thank you.

robtillaart

Please note that tt = pow(V, 0.16); is called 1500 times in the above example for only 15 different values, that is rather inefficient math - but yes it could be worse ;)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Quote
Please note that tt = pow(V, 0.16); is called 1500 times in the above example for only 15 different

I'm pretty sure that the compiler would notice that, too. In the machine code, that would have been moved out of the inner loop, since in that loop the value never changes. Unless V or tt are marked volatile.

robtillaart

Quote
I'm pretty sure that the compiler would notice that, too. In the machine code, that would have been moved out of the inner loop, since in that loop the value never changes. Unless V or tt are marked volatile.


V changes in the inner loop, thats why it is called 1500 times see code below

Code: [Select]

int x = 0;

void setup()
{
  Serial.begin(115200);

  for (int T = 0; T < 100; T++)
  {
    for (int V = 0; V < 15; V++)
    {
      float tt = pov(V);
      Serial.print(tt);
      Serial.print("\t");
    }
    Serial.println();
  }
  Serial.println(x);
}

void loop()
{
}

float pov(float V)
{
  x++;
  return V * V;
}


This would be more efficient;
Code: [Select]

float lookupPow[15];

void setup()
{
  Serial.begin(115200);

  // fill the lookup array
  for (int V = 0; V < 15; V++)
  {
    lookupPow[V] = pow(V, 0.16);
  }

  for (int T = 0; T < 100; T++)
  {
    for (int V = 0; V < 15; V++)
    {
      float tt = lookupPow[V];
      float Windchill  = 35.74 + 0.6215*T - 35.75*tt + 0.4275*T*tt;
      Serial.print(Windchill);
      Serial.print("\t");
    }
    Serial.println();
  }
}

void loop()
{
}

there are more optimizations possible but they are outside the scope of this thread.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up