资源描述:
《数值分析实验[2]》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、《数值分析课程设计》报告一、题目出实验给出数据表X().0()」0.2().3().50.81.0Y1.00.410.500.610.912.022.46试求3次、4次多项式的曲线拟合,再根据数据曲线形状,求一个另外函数的拟合曲线,用图示数据曲线及相应的三种拟合曲线。二.曲线拟合的最小二乘法原理由已知的离散数据点选择与实验点误差最小的曲线s(x)=Q00O(兀)+aV(兀)+…+an(pn(x)称为曲线拟合的最小二乘法。若记m(幻,狄)二吗ypj(可Mk(xi),/=0(/,%)=工Xxjjgcpk(兀)三dk/=0上
2、式可改写为£(加為)勺=久;伙-0,1,...’)这个方程成为法方程,可写成距阵j=O形式Ga=d其屮「(%,%)(00,0)…(0o,久)「(0,00)(0,0)…(0久)O=••••••••(久,久)(久,0)…(©,%)三、解题步骤及运行代码根据所给数据在坐标上绘出散点图(1)3次拟合曲线令s(x)=a。+axx+a2x2+a3x3%(x)=1,0(x)=x,(p2(x)=x2.(p3(x)=x故y6(0(),0))=工0=7,/=()6(%,%)=(®,0())=zc()ixi=2.9,J=()66(0002)=
3、(02,Oo)=工©斤=2.03,(00,©)=(0,00)=工©#=1.673,z=o/=06(01,0)=工©X;=2.03,6(0,02)=(久,0)=工朋=1.673,心06@,03)=(03,0)二工%/=01=06;=1.4819,(色,久)=(%,02)=工0f=1-36169/=06(©,件)=工0兀(02,02)=工0兀:=1-4819,/=0=1.278563,i=0(几%)=7.91,(几®)=4.855,CT®)=4.0593,(几©)=4.059372.92.92.032.031.673a()7.
4、912.031.6731.6731.48191.48191.36169a34.8554.05931.6731.48191.361691.2785633.62887o()=0.9266,ax=-4.6591,a2=12.8147,a3=-6.6221于是拟合曲线为:y=0.9266—4.6591%+12.8147%2—6.6221/用excel做拟合曲线如下:输入代码:X二[0.00.10.20.30.50.81.0];y=[1.00.410.500.610.912.022.46];fl=polyfit(x,y,3)得到结果
5、:fl二-6.622112.8147-4.65910.9266运行代码如下:x=[0.00.10.20.30.50.81.0];y二[1.00.410.500.610.912.022.46];fl二polyfit(x,y,3);xx=x(1):0.1:x(length(x));yy=polyval(fl,xx);plot(xx,yy,holdon;plot(x,y,,x,);xlabcl('x');ylabel('y');legend(,插值点',3次曲线拟合')(2)4次拟合曲线解题过程:令5(x)=+a{x+a2x2+
6、a3x3+a4x4,%(x)=l,(p}{x)=x,^92(x)=x2,66%(兀)二疋,04(x)二兀4,(0),00)=工©=7,@),5)=(%,%)=工①兀=2.9,/=()i=()66(00,02)=(02®)=工©分=2.03,(00,03)=(03,0o)=工©f=1-6731=0/=06(0()04)=(%0())=1.4819,(©OX(羽,0)i・36169,@,0)=工①兀;=2.03/=()66(0,02)=(02,0)=工©#=1673,(0,03)=(03,0)=工©斤=1.4819,/=0/=
7、06(02,©)=(03,02)==1.36169,i=066(%,02)=工©兀4=1.4819,(%,03)=工©#=1.278563‘(^4,^4)=1.17175心0/=()(/,%)=7.91,(/,©)=4.855,(/,%)=4.0593,(/,©)=4.0593(./>4)=3.350_72.92.031.6731.4819_^o"・7.91_2.92.031.6731.48191.361694.8552.031.6731.48191.361691.27856a2—4.05931.6731.48191.36
8、1691.278561.21776偽3.62891.48191.361691.278561.217761.17175__^4__3.350求得q()=0.9427,a.=-5.2987,a2=16.2747,a3=-12.3348,a4=2.8853,所以,4次拟合曲线:y=0.9427-5.2987%