MATLAB Question The average monthly precipitation (in.) for Bostona and Seattle
ID: 3759130 • Letter: M
Question
MATLAB Question
The average monthly precipitation (in.) for Bostona and Seattle during 2012 are given in the vectors below.
BOS=[2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4,10 2.62 1.01 5.93]
SEA=[6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85]
where the elements in the vectors are in the order of the months (January, February, etc.) Write a program in a script file to answer the following.
(a) Calculate the total precipitation for the year and monthly average precipitation in each city.
(b) How many months was the precipitation above average in each city?
(c) How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle?
Using the data and results from previous problem, use Matlab to create and display a table with the headings and the precipitation for each month as shown below. Use fprintf() statements to display this information and format it appropriately.
Explanation / Answer
BOS=[2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93];
SEA=[6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85];
fprintf('Total precipitation of the year for Boston is: %8.2f ', sum(BOS));
fprintf('Monthly average precipitation for Boston is: %8.2f ', mean(BOS));
fprintf('Total precipitation of the year for Boston is: %8.2f ', sum(SEA));
fprintf('Monthly average precipitation for Boston is: %8.2f ', mean(SEA));
temp = mean(BOS) < BOS;
count = sum(temp);
fprintf('The number of months with precipitation above the average precipitation in Boston is: %i ', count);
temp = mean(SEA) < SEA;
count = sum(temp);
fprintf('The number of months with precipitation above the average precipitation in Seattle is: %i ', count);
months = BOS < SEA;
display (find(months == 1));
display(' Monthly Precipitation');
display('Boston Seattle');
i = 1;
while i <= 12
fprintf('%.2f %.2f ', BOS(i), SEA(i));
i = i + 1;
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.