%Problem 6 %Use Matlab polyfit function %********************************************************************* function[]=problem6() %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, 'v') %******************************************* %CUBIC, 3 indicates a cubic %****************************************** p=polyfit(xData, yData, 3); %plot information yPlot=polyval(p, xPlot); plot( xPlot, yPlot, 'd'); %******************************************* %degree 8 approx polynomials, %******************************************* p=polyfit(xData, yData, 8); %plot information yPlot=polyval(p, xPlot); plot(xPlot, yPlot, 'g'); %******************************************* %using the SPLINE function on every 6th point in yData %******************************************* counter=1; yData2=zeros(1,12); %extract every 6 element out of the original data array for i=1:6:67 yData2(counter)=yData(i); counter=counter+1; end xData2=1:6:67; tt=1:0.1:67; %find x piece xPlot2=ppval(spline(xData2,yData2), tt); %plot plot(tt, xPlot2, 'r'); hold off end