资源描述:
《数值分析,任玉杰教程课后题》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、杨颖应用数学131802班2013180502286.21.已知函数在[1,7]上具有二阶连续导数,,且满足条件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(
2、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.给出节点数据,,,作五阶牛顿插值多项式和差商,并写出其估计误差的公式.解(1)保存名为newpoly.m的M文件.function[A,C,L,wcgs,Cw]=newploy(X,Y)n=length(X);A=zeros(n,n);A(
3、:,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(
4、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
5、.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+(246736293
6、371003*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+7637300625126
7、911/36028797018963968))/720Cw=0.0014-0.0030-0.01530.03230.0133-0.02960.0003即L=1.09683171-4.71845673x+3.50633362x+2.22937587x-0.04788204x-0.19563585x估计其误差的公式为=(x+3.15)(x+1.00)(x-0.01)(x-1.02)(x-2.03)(x-3.25),6.41.给定函数在点x=,处的函数值,,和导数值,,且,求函数在点处的三阶埃尔米特插值多项式和误差公式。解
8、(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