利用MATLAB进行直线拟合的程序

源程序:

% 初始数据
x=[0.00310,0.00313,0.00316,0.00319,0.00322,0.00326,0.00329,0.00332];
y=[9.985,9.893,9.810,9.729,9.646,9.581,9.507,9.451];
% 拟合直线y=p(1)*x+p(2)
p=polyfit(x,y,1);
% 显示拟合前后直线,其中方框为拟合前数据,直线为拟合后的直线
yy=polyval(p,x);
plot(x,y,'s',x,yy)
%拟合的直线方程
poly2sym(p,'x')


结果:

ans =

4648504458470549*x-396243168544487872

>> vpa(ans,8)

ans =

.46485045e16*x-.39624317e18

你可能感兴趣的:(XP,matlab,plot)