Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The heat index HI, calculated from the air temperature and relative humidity, is the apparent temperature felt by the body. An equation used by the

The heat index HI, calculated from the air temperature and relative humidity, is the apparent temperature felt by the body. An equation used by the National Weather Service for calculating the HI is given by: HI = C1 + C2T + C3R + C4TR + C5T 2 + C6R 2 + C7T 2R + C8TR2 + C9T 2R 2 Where T is the temperature in F, and R is the relative humidity in integer percentage. Write a MATLAB program that reads a file having the following format:

Temperature 80 82 84 86 88 90 92 94

Relative Humidity 50 55 60 65 70 75

Coefficients -42.379 2.04901523 10.14333127 -0.22475541 -6.83783e-3 - 5.481717e-2 1.22874e-3 8.5282e-4 -1.99e-06

In the file above, it is unknown ahead of time how many numbers will be on the Temperature and Relative Humidity lines. There will be exactly nine numbers on the Coefficients line. In the example above, the numbers wrapped to the next line, but in reality, all the Coefficient numbers will be on the same line. All the numbers will likely be different than shown in the file above. Next, compute HI for each combination of T and R. Your results should be written to a file as shown below:

Temperature (F)

1 80 82 84 86 88 90 92 94

Relative Humidity (%)

50 81 83 85 88 91 95 99 103

55 81 84 86 89 93 97 101 106

60 82 84 88 91 95 100 105 110

65 82 85 89 93 98 103 108 114

70 83 86 90 95 100 106 112 119

75 84 88 92 97 103 109 116 124

Each of the columns above is 10 characters wide. Here is a printout of what the user should see while running your program at the command window:

>> miniproject input filename : input.txt

output filename : output.txt

Hints One of the sticky problems that you must deal with is not knowing how many temperatures or relative humidities will be in the input file. An elegant solution to this problem is the built-in MATLAB function repmat. For the numbers shown in the example above, I recommend using repmat to build a Tmat matrix like this:

Tmat =

80 82 84 86 88 90 92 94

80 82 84 86 88 90 92 94

80 82 84 86 88 90 92 94

80 82 84 86 88 90 92 94

80 82 84 86 88 90 92 94

80 82 84 86 88 90 92 94

Notice that Tmat above has as many rows as there are relative humidity numbers, and this number can be found with the built-in function length. Also use repmat to build an Rmat matrix, having as many columns as you have temperature numbers:

Rmat =

50 50 50 50 50 50 50 50

55 55 55 55 55 55 55 55

60 60 60 60 60 60 60 60

65 65 65 65 65 65 65 65

70 70 70 70 70 70 70 70

75 75 75 75 75 75 75 75

Now its easy to do an element-by-element calculation and calculate all the HI numbers, using just one line of code. A final problem is constructing the call to fprintf, not knowing how many numbers you will be printing ahead of time. Repmat is, again, an elegant solution to this problem. For example, the following line of code will create a format string, suitable for using in fprintf, that will print n numbers per row:

format_string = [repmat('%10.0f',1,n) ' '];

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

Question How is life insurance used in a DBO plan?

Answered: 1 week ago