All pastes #812997 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-12-12 04:43 UTC
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, '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