Pages: [1]   Go Down
Author Topic: windchill formula uses exponents, how do we do that?  (Read 1508 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the windchill formula uses exponents

Code:
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?
Logged

Montreal
Offline Offline
Full Member
***
Karma: 4
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
pow(V, 0.16f);
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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(){}
« Last Edit: June 30, 2013, 03:51:20 pm by grendle » Logged

London
Offline Offline
Edison Member
*
Karma: 48
Posts: 1460
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the windchill formula uses exponents

Code:
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.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the windchill formula uses exponents

Code:
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  smiley-lol
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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()
{
}
« Last Edit: July 02, 2013, 12:00:19 pm by robtillaart » Logged

Rob Tillaart

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

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
Logged

Rob Tillaart

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50039
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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.
Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: