您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 数值分析,任玉杰教程课后题
杨颖应用数学131802班2013180502286.21.已知函数)(xf在[1,7]上具有二阶连续导数,5)(xf,且满足条件f(x)=1,f(7)=12,.求线性插值多项式和函数值f(3.5),并估计其误差.解:输入程序X=[1,7];Y=[1,12];l01=poly(X(2))/(X(1)-X(2)),l11=poly(X(1))/(X(2)-X(1)),l0=poly2sym(l01),l1=poly2sym(l11),P=l01*Y(1)+l11*Y(2),L=poly2sym(P),x=3.5;Y=polyval(P,x)运行后输出基函数l0和l1及其插值多项式的系数向量P(略)、插值多项式L和插值Y为l01=-0.16671.1667l11=0.1667-0.1667l0=7/6-x/6l1=x/6-1/6P=1.8333-0.8333L=(11*x)/6-5/6Y=5.58336.35.给出节点数据03.37)15.3(f,05.23)25.3(,06.17)03.2(,03.2)02.1(,05.1)01.0(,24.7)00.1(fffff,,作五阶牛顿插值多项式和差商,并写出其估计误差的公式.解(1)保存名为newpoly.m的M文件.function[A,C,L,wcgs,Cw]=newploy(X,Y)n=length(X);A=zeros(n,n);A(:,1)=Y';s=0.0;p=1.0;q=1.0;c1=1.0;forj=2:nfori=j:nA(i,j)=(A(i,j-1)-A(i-1,j-1))/(X(i)-X(i-j+1));endb=poly(X(j-1));q1=conv(q,b);c1=c1*j;q=q1;endC=A(n,n);b=poly(X(n));q1=conv(q1,b);fork=(n-1):-1:1C=conv(C,poly(X(k)));d=length(C);C(d)=C(d)+A(k,k);endL(k,:)=poly2sym(C);Q=poly2sym(q1);symsMwcgs=M*Q/c1;Cw=q1/c1;(2)输入MATLAB程序X=[-3.15-1.000.011.022.033.25];Y=[37.037.241.052.0317.0623.05];[A,C,L,wcgs,Cw]=newpoly(X,Y)运行后输出差商矩阵A,五阶牛顿插值多项式L及其系数向量C,插值余项公式L及其向量Cw如下A=37.0300000007.2400-13.855800001.0500-6.12872.44530002.03000.97033.51440.25640017.060014.88126.88661.11290.1654023.05004.9098-4.4715-3.5056-1.0867-0.1956C=-0.1956-0.04792.22943.5063-4.71851.0968L=-(3524262145772209*x^5)/18014398509481984-(431283038958129*x^4)/9007199254740992+(5020108164096803*x^3)/2251799813685248+(246736293371003*x^2)/70368744177664-(5312509994841131*x)/1125899906842624+154365339321353/140737488355328wcgs=(M*(x^6-(54*x^5)/25-(6869*x^4)/625+(204645801275343*x^3)/8796093022208+(5397560409786347*x^2)/562949953421312-(5994280682419117*x)/281474976710656+7637300625126911/36028797018963968))/720Cw=0.0014-0.0030-0.01530.03230.0133-0.02960.0003即L=1.09683171-4.71845673x+3.50633362x2+2.22937587x3-0.04788204x4-0.19563585x5估计其误差的公式为)(5xR=!)()(66f(x+3.15)(x+1.00)(x-0.01)(x-1.02)(x-2.03)(x-3.25),),(3.253.15-6.41.给定函数)(xf在点x0=6/,4/1x处的函数值5.0)(0xf,1707.0)(1xf,和导数值0866.0)(0'xf,1707.0)(1'xf,且1)()4(xf,求函数)(xf在点处的三阶埃尔米特插值多项式和误差公式。解(1)保存名为hermite.m的M文件.function[Hc,Hk,wcgs,Cw]=hermite(X,Y,Y1)m=length(X);n=1;s=0;H=0;q=1;c1=1;L=ones(m,m);G=ones(1,m);fork=1:n+1V=1;fori=1:n+1ifk~=is=s+(1/(X(k)-X(i)));V=conv(V,poly(X(i)))/(X(k)-X(i));endh=poly(X(k));g=(1-2*h*s);G=g*Y(k)+h*Y1(k);endH=H+conv(G,conv(V,V));b=poly(X(k));b2=conv(b,b);q=conv(q,b2);t=2*n+2;Hc=H;Hk=poly2sym(H);Q=poly2sym(q);endfori=1:tc1=c1*i;endsymsM,wcgs=M*Q/c1;Cw=q/c1;(2)在MATLAB工作窗口输入程序X=[pi/6,pi/4];Y=[0.5,0.7071];Y1=[0.8660,0.7071];[Hc,Hk,wcgs,Cw]=hermite(X,Y,Y1)运行后输出三阶埃尔米特插值多项式Hk及其系数向量Hc,误差公式wcgs及其系数向量Cw如下Hc=96.2945-166.742494.7792-16.9739Hk=(3388060314322531*x^3)/35184372088832-(5866727782923391*x^2)/35184372088832+(6669496320254561*x)/70368744177664-2388870952879233/140737488355328wcgs=(M*(x^4-(5*pi*x^3)/6+(1427607315983063*x^2)/562949953421312-(4848606114706415*x)/4503599627370496+6092938140044889/36028797018963968))/24Cw=0.0417-0.10910.1057-0.04490.0070当1)()4(xf=M时的误差公式为R=0.04174x-0.1091x3+0.1057x2-0.0449x+0.00706.51.作函数22511)(xxf在区间[-5,5]上的n次拉格朗日插值多项式)(xLn)10,8,6,4,2(n的图形,并讨论插值多项式)(xLn的次数与误差)(xRn的关系.解将计算n次拉格朗日插值多项式)(xLn的值的MATLAB程序保存名为lagr1.m的M文件.functiony=lagr1(x0,y0,x)n=length(x0);m=length(x);fori=1:mz=x(i);s=0.0;fork=1:np=1.0;forj=1:nifj~=kp=p*(z-x0(j))/(x0(k)-x0(j));endends=p*y0(k)+s;endy(i)=s;End在MATLAB工作窗口输入程序m=101;x=-5:10/(m-1):5;y=1./(1+25*x.^2);z=0*x;plot(x,z,'r',x,y,'k-'),gtext('y=1/(1+25*x^2)'),pausen=3;x0=-5:10/(n-1):5;y0=1./(1+25*x0.^2);y1=lagr1(x0,y0,x);holdon,plot(x,y1,'g'),gtext('n=2'),pause,holdoffn=5;x0=-5:10/(n-1):5;y0=1./(1+25*x0.^2);y2=lagr1(x0,y0,x);holdon,plot(x,y2,'b:'),gtext('n=4'),pause,holdoffn=7;x0=-5:10/(n-1):5;y0=1./(1+25*x0.^2);y3=lagr1(x0,y0,x);holdon,plot(x,y3,'r'),gtext('n=6'),pause,holdoffn=9;x0=-5:10/(n-1):5;y0=1./(1+25*x0.^2);y4=lagr1(x0,y0,x);holdon,plot(x,y4,'r:'),gtext('n=8'),pause,holdoffn=11;x0=-5:10/(n-1):5;y0=1./(1+25*x0.^2);y5=lagr1(x0,y0,x);holdon,plot(x,y5,'m'),gtext('n=10')title('高次拉格朗日插值的振荡')回车运行后,便会逐次画出)1/(12xy在区间]5,5[上的n次拉格朗日插值多项式)(xLn)10,8,6,4,2(n的图形从图中可以看出,对于较大的|x|,随着n的增大,Ln(x)振荡越来越大,事实上可以证明,仅当(x是某一个正数)时,才有)(limxLnn=g(x).而在此区间外,)(xLn是发散的。由于在大范围内使用高次插值多项式逼近的效果往往不理想,从而促使人们转而寻求简单的低次插值方法。从图中可以看出,对于较大的|x|,随着n的增大,Ln(x)振荡越来越大,事实上可以证明,仅当(x是某一个正数)时,才有)(limxLnn=g(x).而在此区间外,)(xLn是发散的。由于在大范围内使用高次插值多项式逼近的效果往往不理想,从而促使人们转而寻求简单的低次插值方法。6.7设函数))432sin3tan(cos()(2xxxf定义在区间],[上,取n=10,按等距节点构造四种插值函数Sn(x).(1)用MATLAB程序计算各小区间中点ix处,作出)(xf及其后三种插值函数,作出节点、插值点、)(xf和四种插值函数的图形;(2)并用MATLAB程序计算各小区间中点处四种插值及其相对误差;(3)用MATLAB程序估计)(maxxfx和Sn(x)在区间],[上的的误差限。解(1)记节点的横坐标5/,hihxi,7,,2,1,0i,插值点)(21121iiixxx,i=6210,,,,编写并保存名为sanli679.m的M文件如下h记节点的横坐标,20,,2,1,0,5.0,5ihihxi插值点)(21121iiixxx,19,,2,1,0i.=tan(cos((3^(1/2)+sin(2*X))./(3+4*X.^2)));YL=lagr1(x0,y0,X);YS=interp1(x0,y0,X,'spline');YH=interp1(x0,y0,X,'pchip');yL=lagr1(x0,y0,x);yX=interp1(x0,y0,x);yS=interp1(x0,y0,x,'spline');yH=interp1(x0,y0,x,'pchip');RL=abs((y-yL)./y);RS=abs((y-yS)./y);RH=abs((y-yH)./y);RX=abs((y-yX)./y);RLj=abs(y-yL);mRLj=mean(RLj);RSj=abs(y-yS);mRSj=
本文标题:数值分析,任玉杰教程课后题
链接地址:https://www.777doc.com/doc-2424375 .html