%Fit using polyfit in matlab for best fit checking plot
table = xlsread(‘Project04′,’Stepped-Shaft Torsion Data, A-E’)
[p S] = polyfit(table(:,1),table(:,2),5)
[yh,d]=polyval(p,table(:,1),S)
% show results
%Problem(b)
figure
plot(table(:,1),table(:,2),’o’)
hold on
plot(table(:,1),yh)
%plot(table(:,1),f1,’r–‘)
legend(‘Original’,’fit’,’f1′)
%Coeff=p =
% 1.0e+03 *
%-2.0574 2.0713 -0.8200 0.1662 -0.0191 0.0023
%Problem(c)
x=[0.05 0.1 0.15 0.2 0.25 0.3]
yh=polyval(p,x)
x,yh
[p,S]=polyfit(table(:,1),table(:,2),1)
yh1=polyval(p,x)
x,yh1
figure
plot(x,yh)
hold on
plot(x,yh1)
%plot(table(:,1),f1,’r–‘)
legend(‘PolyStandarddata’,’Linear’,’f1′)