预览加载中,请您耐心等待几秒...
1/9
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

曲线拟合的最小二乘法 1、 %采用二次多项式拟合 %a的输出为多项式各项系数 %b为拟合曲线各点函数值 %phi为输出的曲线拟合函数 x=0:5:55; y=[01.272.162.863.443.874.154.374.514.584.024.64]; a=polyfit(x,y,2) b=polyval(a,x) symst phi=a(1)*t^2+a(2)*t+a(3) 运行结果: >>leastway a= -0.00240.20370.2305 b= Columns1through5 0.23051.18942.02932.75023.3521 Columns6through10 3.83494.19874.44354.56934.5760 Columns11through12 4.46374.2324 phi= 2 -0.00238051948051948162t+0.203690809190809258t+0.230467032967031749 2、 %采用三次多项式拟合 x=0:5:55; y=[01.272.162.863.443.874.154.374.514.584.024.64]; a=polyfit(x,y,3) b=polyval(a,x) symst phi=a(1)*t^3+a(2)*t^2+a(3)*t+a(4) 运行结果: >>leastway a= 0.0000-0.00520.26340.0178 b= Columns1through5 0.01781.20872.16462.91133.4745 Columns6through10 3.88004.15364.32114.40824.4407 Columns11through12 4.44444.4450 phi= 32 0.0000343641543641541613t-0.00521556221556219567t +0.263398527398526872t+0.0178388278388323038 3、 %delta为拟合函数值与原函数值的误差 clc clear x=0:5:55; y=[01.272.162.863.443.874.154.374.514.584.024.64]; a=polyfit(x,y,3); b=polyval(a,x); forj=1:12 delta=b(j)-y(j) end symst phi=a(1)*t^3+a(2)*t^2+a(3)*t+a(4) 运行结果: delta= 0.0178 delta= -0.0613 delta= 0.0046 delta= 0.0513 delta= 0.0345 delta= 0.0100 delta= 0.0036 delta= -0.0489 delta= -0.1018 delta= -0.1393 delta= 0.4244 delta= -0.1950 phi= 32 0.0000343641543641541613t-0.00521556221556219567t +0.263398527398526872t+0.0178388278388323038 4、 %采用四次多项式拟合与三次多项式拟合进行比较 %输出其与原函数值的误差再与之前输出的三次与原函误差进行比较 %delta4为四次与原函的误差 clc clear x=0:5:55; y=[01.272.162.863.443.874.154.374.514.584.024.64]; a=polyfit(x,y,4); b=polyval(a,x) forj=1:12 delta4=b(j)-y(j) end symst phi=a(1)*t^4+a(2)*t^3+a(3)*t^2+a(4)*t+a(5) 运行结果: b= Columns1through5 0.06041.17392.12202.89453.4900 Columns6through10 3.91624.18984.33664.39144.3981 Columns11through12 4.40954.4876 delta4= 0.0604 delta4= -0.0961 delta4= -0.0380 delta4= 0.0345 delta4= 0.0500 delta4= 0.0462 delta4= 0.0398 delta4= -0.0334 delta4= -0.1186 delta4= -0