欢迎来到天天文库
浏览记录
ID:6706365
大小:35.71 KB
页数:9页
时间:2018-01-23
《数值分析实验作业matlab编程课题八》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、曲线拟合的最小二乘法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)symstphi=a(1)*t^2+a(2)*t+a(3)运行结果:>>leastwaya=-0.00240.20370.2305b=Columns1through50.23051.18942.02932
2、.75023.3521Columns6through103.83494.19874.44354.56934.5760Columns11through124.46374.2324phi=2-0.00238051948051948162t+0.203690809190809258t+0.2304670329670317492、%采用三次多项式拟合x=0:5:55;y=[01.272.162.863.443.874.154.374.514.584.024.64];a=polyfit(x,y,3)b=pol
3、yval(a,x)symstphi=a(1)*t^3+a(2)*t^2+a(3)*t+a(4)运行结果:>>leastwaya=0.0000-0.00520.26340.0178b=Columns1through50.01781.20872.16462.91133.4745Columns6through103.88004.15364.32114.40824.4407Columns11through124.44444.4450phi=320.0000343641543641541613t-0.0052
4、1556221556219567t+0.263398527398526872t+0.01783882783883230383、%delta为拟合函数值与原函数值的误差clcclearx=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:12delta=b(j)-y(j)endsymstphi=a(1)*t^3+a(2)*t^2+a(3)*t+a(4)运行结果:
5、delta=0.0178delta=-0.0613delta=0.0046delta=0.0513delta=0.0345delta=0.0100delta=0.0036delta=-0.0489delta=-0.1018delta=-0.1393delta=0.4244delta=-0.1950phi=320.0000343641543641541613t-0.00521556221556219567t+0.263398527398526872t+0.01783882783883230384、%采
6、用四次多项式拟合与三次多项式拟合进行比较%输出其与原函数值的误差再与之前输出的三次与原函误差进行比较%delta4为四次与原函的误差clcclearx=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:12delta4=b(j)-y(j)endsymstphi=a(1)*t^4+a(2)*t^3+a(3)*t^2+a(4)*t+a(5)运行结果:b=Column
7、s1through50.06041.17392.12202.89453.4900Columns6through103.91624.18984.33664.39144.3981Columns11through124.40954.4876delta4=0.0604delta4=-0.0961delta4=-0.0380delta4=0.0345delta4=0.0500delta4=0.0462delta4=0.0398delta4=-0.0334delta4=-0.1186delta4=-0.1819
8、delta4=0.3895delta4=-0.1524phi=-6430.60256410256410728810t-0.0000319178969178975504t2-0.00293227466977464190t+0.238069314944314520t+0.06044871794871947705、%分别采用二次、四次、六次、九次多项式拟合并画出其曲线进行比较clcclearx=0:5:55;y=[01.272.162.863.443.874.154.374
此文档下载收益归作者所有