Go Down

### Topic: windchill formula uses exponents, how do we do that? (Read 4759 times)previous topic - next topic

#### grendle

##### Jun 30, 2013, 10:18 pm
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

#1
##### Jun 30, 2013, 10:27 pm
Code: [Select]
`pow(V, 0.16f);`

#### grendle

#2
##### Jun 30, 2013, 10:40 pmLast 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

#3
##### Jul 01, 2013, 05:45 am

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

#4
##### Jul 01, 2013, 08:18 pm

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 pmLast 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

#6
##### Jul 02, 2013, 05:07 am

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  . this is sweet and this is the format im gonna use. thank you.

#### robtillaart

#7
##### Jul 02, 2013, 07:02 pm
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

#8
##### Jul 03, 2013, 10:52 am
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

#9
##### Jul 03, 2013, 08:16 pm
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