Technology Programming

Calculating Wind Chill with PHP

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:

<?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
RELATED POSTS on "Technology"
Blitzerwarner: Could You Escape the Speed Cameras?
Blitzerwarner: Could You Escape the Speed Cameras?
What Makes a Perfect Web Design Company?
What Makes a Perfect Web Design Company?
Inside No-Fuss Products In Gaming Computers
Inside No-Fuss Products In Gaming Computers
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Free Music Players For Websites
Free Music Players For Websites
'See How NCP Tracks Down Fake Ration Card Holders'
'See How NCP Tracks Down Fake Ration Card Holders'
You Can Stop Panic Attacks in Just two Minutes
You Can Stop Panic Attacks in Just two Minutes
WordPress Blog to WP Site! A Journey to Online Success
WordPress Blog to WP Site! A Journey to Online Success
Videos will give your business portal an extra leverage
Videos will give your business portal an extra leverage
Excellent Ways To Make Weight Loss Work For You
Excellent Ways To Make Weight Loss Work For You
Five Notable Differences between National and International Logo Designs
Five Notable Differences between National and International Logo Designs
Who Should Your Phoenix Web Design Client Be?
Who Should Your Phoenix Web Design Client Be?
White Papers & Other Documents - including ALFLB
White Papers & Other Documents - including ALFLB
Google Analytics Tips
Google Analytics Tips
Want To Make Your Website Faster? Follow These Steps
Want To Make Your Website Faster? Follow These Steps
The Starting of Couture Apparel
The Starting of Couture Apparel
Choose Custom Website Design Services
Choose Custom Website Design Services
Choosing the Right Joomla CMS Developer
Choosing the Right Joomla CMS Developer
A Look at SQL Server Denali AlwaysOn
A Look at SQL Server Denali AlwaysOn
4 Tips to Choose the Perfect Flash Animation Course
4 Tips to Choose the Perfect Flash Animation Course

Leave Your Reply

*