Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. The maximum daily temperature (in °F) for Chicago and San Francisco dur- ing

ID: 3870276 • Letter: 6

Question

6. The maximum daily temperature (in °F) for Chicago and San Francisco dur- ing the month of August 2009 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration) TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73 79 82 72 66 71 69 66 66] TSF=[69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68 69 71 70 89 95 90 66 69] Write a program in a script file to answer the following (a) Calculate the average temperature for the month in each city. (b) How many days was the temperature above the average in each city? (c) How many days, and on which dates in the month, was the temperature in San Francisco lower than the temperature in Chicago? (d) How many days, and on which dates in the month, was the temperature the same in both cities?

Explanation / Answer

%matlab code part a

clc;clear all;close all;

TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73 79 82 72 66 71 69 66 66 ];

TSF=[69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68 69 71 70 89 95 90 66 69];

sum1=0;

sum2=0;

for i=1:length(TCH)

sum1=sum1+TCH(i);

sum2=sum2+TSF(i);

end

fprintf('Chicago Average Temperature: %d degrees. ',round(sum1/length(TCH)));

fprintf('San Francisco Average Temperature: %d degrees. ',round(sum2/length(TCH)));


%matlab code part b

clc;clear all;close all;

TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73 79 82 72 66 71 69 66 66 ];

TSF=[69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68 69 71 70 89 95 90 66 69];

sum1=0;

sum2=0;

for i=1:length(TCH)

sum1=sum1+TCH(i);

sum2=sum2+TSF(i);

end

avg1=round(sum1/length(TCH));

avg2=round(sum2/length(TCH));

count1=0;

count2=0;

for i=1:length(TCH)

if(TCH(i)>avg1)

count1=count1+1;

end

if(TSF(i)>avg2)

count2=count2+1;

end;

end

fprintf('Days above Chicago average temperature: %d days. ',count1);

fprintf('Days above San Francisco average temperature: %d days. ',count2);


%matlab code part c

clc;clear all;close all;

TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73 79 82 72 66 71 69 66 66 ];

TSF=[69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68 69 71 70 89 95 90 66 69];

sum=0;

for i=1:length(TCH)

if(TSF(i)<TCH(i))

sum=sum+1;

end

end

fprintf('Days cooler in San Francisco than Chicago: %d days. ',sum);

%matlab code part d

clc;clear all;close all;

TCH=[75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81 79 73 69 73 79 82 72 66 71 69 66 66 ];

TSF=[69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73 72 79 68 68 69 71 70 89 95 90 66 69];

count=0;

for i=1:length(TCH)

if(TSF(i)==TCH(i))

count=count+1;

end

end

fprintf('Count of days with same temperature in San Francisco than Chicago: %d days. ',count);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote