I live in Wisconsin, and this winter has certainly been one of extreme temperatures. While Wisconsin has always been cold, this has been a particularly cold one. Today my children's school is close for the third time this year not for snow, but for extreme cold.
This got me thinking about wind chill. You see the temperature alone (in the -20 to 0 range) isn't cold enough to shut down everything.
It's the addition of the wind that makes the temperatures feel so terribly frigid and dangerous. This inspired me to write a little program to calculate the wind chill.
According to mental floss, the formula for calculating the wind chill is: Wind Chill = 35.74 + 0.6215T – 35.75(V^0.16) + 0.4275T(V^0.16)
In this formula T is the temperature in Fahrenheit and V is the speed of the wind in miles per hour. If you need to convert Celsius to Fahrenheit, have a look at this program.
Here is the program I wrote to perform the wind chill calculations based on this formula:
Let's go through this line by line so you understand what the program is doing.
The first line <?php is how we start every PHP program.
In the second line we create the variable $T. This is the variable for temperature. In the program above I have set the temperature to be -10 because that is what the temperature is at my house today!
In the third line, we set the variable $V. This variable represents the speed of the wind in miles per hour. I have set this variable to be 18, because today we have 18mph winds.
In the fourth line we create a variable called $a. I use this variable to do the math that requires exponents, so the formula on the next line will be cleaner. In our case the math it is preforming is $V which we have set to 18, raised to the power of 0.16, which is a fixed value. We do this using the pow () function.
In the fifth line we actually calculate the wind chill. We take our original formula (Wind Chill = 35.74 + 0.6215T – 35.75(V^0.16) + 0.4275T(V^0.16)) and we convert it to use our new PHP variables, and we come up with $wc = 35.74 + (0.6215 * $T) -(35.75 *$a) + (0.4275*$T*$a)
If we were to run the program at this point it would return the temperature as -34.033690580727, however we probably don't want it to so many decimal places, so now we are going to add a line to round it. We do this using the round () function. This makes the next line of our program: $wcr = round($wc);
Next we have to add a line where the program actually tells us what it calculated. We do this simply using echo. Running our final program will output the following:
Finally we end with a ?> to close out the PHP program.
Although if you live in a cold area, weather reports usually already include the wind chill, you can use a simple program like this to calculate the wind chill on your own. You can even modify this program slightly to allow the user to input their own values for temperature and wind speed, or perhaps to convert the entire thing into Celsius or to use KPH instead of MPH.
This got me thinking about wind chill. You see the temperature alone (in the -20 to 0 range) isn't cold enough to shut down everything.
It's the addition of the wind that makes the temperatures feel so terribly frigid and dangerous. This inspired me to write a little program to calculate the wind chill.
According to mental floss, the formula for calculating the wind chill is: Wind Chill = 35.74 + 0.6215T – 35.75(V^0.16) + 0.4275T(V^0.16)
In this formula T is the temperature in Fahrenheit and V is the speed of the wind in miles per hour. If you need to convert Celsius to Fahrenheit, have a look at this program.
Here is the program I wrote to perform the wind chill calculations based on this formula:
<?php
$T = -10;
$V = 18;
$a = pow($V, 0.16);
$wc = 35.74 + (0.6215 * $T) -(35.75 *$a) + (0.4275*$T*$a);
$wcr = round($wc);
echo "The wind chill temperature is $wcr degrees Fahrenheit";
?>
Let's go through this line by line so you understand what the program is doing.
The first line <?php is how we start every PHP program.
In the second line we create the variable $T. This is the variable for temperature. In the program above I have set the temperature to be -10 because that is what the temperature is at my house today!
In the third line, we set the variable $V. This variable represents the speed of the wind in miles per hour. I have set this variable to be 18, because today we have 18mph winds.
In the fourth line we create a variable called $a. I use this variable to do the math that requires exponents, so the formula on the next line will be cleaner. In our case the math it is preforming is $V which we have set to 18, raised to the power of 0.16, which is a fixed value. We do this using the pow () function.
In the fifth line we actually calculate the wind chill. We take our original formula (Wind Chill = 35.74 + 0.6215T – 35.75(V^0.16) + 0.4275T(V^0.16)) and we convert it to use our new PHP variables, and we come up with $wc = 35.74 + (0.6215 * $T) -(35.75 *$a) + (0.4275*$T*$a)
If we were to run the program at this point it would return the temperature as -34.033690580727, however we probably don't want it to so many decimal places, so now we are going to add a line to round it. We do this using the round () function. This makes the next line of our program: $wcr = round($wc);
Next we have to add a line where the program actually tells us what it calculated. We do this simply using echo. Running our final program will output the following:
The wind chill temperature is -34 degrees Fahrenheit
Finally we end with a ?> to close out the PHP program.
Although if you live in a cold area, weather reports usually already include the wind chill, you can use a simple program like this to calculate the wind chill on your own. You can even modify this program slightly to allow the user to input their own values for temperature and wind speed, or perhaps to convert the entire thing into Celsius or to use KPH instead of MPH.
SHARE