In Matlab:
A list of average monthly high temperatures for the city of Monroe Louisiana is given below:
Month Temperature (in◦F)
January 56
February 60
March 69
April 77
May 84
June 90
July 94
August 94
September 88
October 79
November 68
December 58
For convenience, label January as 1, February as 2, and so forth. Then fit a quadratic and fourth-degree polynomials through these data on the same figure window. Include the label and a legend. Based on your fourth order polynomial fit, estimate the temperature on August 10.
MATLAB Code:
close all
clear
clc
m = 1:12;
t = [56 60 69 77 84 90 94 94 88 79 68 58];
p2 = polyfit(m, t, 2);
p4 = polyfit(m, t, 4);
mm = linspace(1,12,365); % 365 days
plot(m, t, 'o', mm, polyval(p2, mm), mm, polyval(p4, mm))
xlabel('Month'), ylabel('Temperature')
legend('Data Points', 'Polynomial (Degree 2)', 'Polynomial (Degree
4)', 'Location', 'northwest')
p4val = linspace(polyval(p4, 8), polyval(p4, 9), 31); % For the
month of August (31 days)
fprintf('Estimated temperature using 4th degree polynomial on
August 10: %f\n', p4val(10)); % Aug. 10
Output:
Estimated temperature using 4th degree polynomial on August 10: 91.123767
Plot:
Get Answers For Free
Most questions answered within 1 hours.