rendered paste body%*********************************************************************
%Csci 2031
%Assignment 6
%Problem 6
%Use Matlab polyfit function
%*********************************************************************
function[]=problem6()
y=[ 111.98
113.54
112.89
110.69
113.62
114.35
118.77
121.19
118.40
121.33
122.67
123.64
124.07
124.49
120.19
120.38
117.50
118.75
120.50
125.09
123.66
121.55
123.90
123.00
122.34
119.65
121.89
120.56
122.04
122.04
121.26
127.17
132.75
132.30
130.33
132.35
132.39
134.07
137.73
138.10
138.91
138.12
140.00
143.75
143.70
134.89
137.26
146.00
143.85
141.43
131.76
135.00
136.49
131.85
135.25
135.03
134.01
126.39
125.00
127.79
124.03
119.90
117.05
122.06
122.22
127.57
132.51
];
%transpose of stock information
yData=y';
xData=1:1:67;
%*******************************************
%best least-squares line, 1 indicates a LINE
%*******************************************
plot(xData, yData, 'o'); hold on
p=polyfit(xData, yData,1);
%plot information
xPlot = 1:1:67;
yPlot = polyval(p, xPlot);
plot(xData, yData, 'b', xPlot, yPlot, 'r')
%*******************************************
%CUBIC, 3 indicates a cubic
%******************************************
p=polyfit(xData, yData, 3);
%plot information
yPlot=polyval(p, xPlot);
plot(xData, yData, 'g', xPlot, yPlot, 'd');
%*******************************************
%degree 8 approx polynomials,
%*******************************************
p=polyfit(xData, yData, 8);
%plot information
yPlot=polyval(p, xPlot);
plot(xData, yData, 'x', xPlot, yPlot, 'd');
end