MATLAB实现曲线拟合

x=[0.5,1.0,1.5,2.0,2.5,3.0]

y=[1.75,2.45,3.81,4.80,7.00,8.60]

解:MATLAB程序如下:

x=[0.5,1.0,1.5,2.0,2.5,3.0];

y=[1.75,2.45,3.81,4.80,7.00,8.60];

p=polyfit(x,y,2)

x1=0.5:0.05:3.0;

y1=polyval(p,x1);

plot(x,y,'*r',x1,y1,'-b')

计算结果为:

p =0.5614 0.8287 1.1560

即所得多项式为y=0.5614x^2+0.08287x+1.15560

posted @ 2017-10-04 20:59  Horse-Ma  阅读(881)  评论(0编辑  收藏  举报