rt=[1 1.4 1.6 2 2.4 2.6 3 3.6 4 4.6 5 6];
>> y=[0.264241 0.408167 0.475069 0.593994 0.691559 0.732615 0.800852 0.874311 0.908422 0.94371 0.959572 0.982649];
>> A=polyfit(rt,y,2)
z=polyval(A,rt);
plot(rt,y,'k+'激隐备,rt,z,'r')
A = -0.0391 0.4073 -0.0800
也就是结果为y=-0.0391*x^2+0.4073*x-0.0800,上面明毁(rt,y,2)的2是指携慎拟合多项式次数为2;
如果是直线的话2改成1就可以了。
[a b]=polyfit(x,y);
yy=a*x+b;
plot(x,y,'.',x,yy)
x=[-2.573 -2.159 -1.741 -1.403 -1.029 -0.699];
y=[0.640 0.844 1.081 1.227 1.446 1.574];
p1=polyfit(x,y,1);
f=poly2str(p1,'x')