x=[1,2,4,7,9,12,13,15,17];
f=[1.5,3.9,6.6,11.7,15.6,18.8,19.6,20.6,21.1];
p=polyfit(x,f,2)
fx_sym=poly2sym(p);
ezplot(fx_sym,[0 20])
hold all
plot(x,f,'r*');
f=[1.5,3.9,6.6,11.7,15.6,18.8,19.6,20.6,21.1];
p=polyfit(x,f,2)
fx_sym=poly2sym(p);
ezplot(fx_sym,[0 20])
hold all
plot(x,f,'r*');
拟合效果下图
x=[1,1.5,2,2.5,3];y=[0.9,1.7,2.2,2.6,3];
p=polyfit(x,y,2);
x1=linspace(min(x),max(x));
y1=polyval(p,x1);
plot(x,y,'*',x1,y1);