数值分析(西北工业大学出版社)第4节 分段插值多项式
- 格式:ppt
- 大小:660.00 KB
- 文档页数:20


插值多项式一、实验目的:熟悉插值多项式构造,掌握数据插值的思想方法,了解用内部函数和掌握编程方法解决实验问题;了解龙格现象,通过拉格朗日插值、分段线性插值以及三次样条插值进行插值效果的比较和分析;掌握上机编程与调试能力。
二、实验内容:给定被插函数()()s i n ,s i n ,c o s x x fx x x e x x =插值区间为[1,8],节点为,1,2...,8i x i i ==,分别用分段线性和Hermite 多项式进行插值。
并和7次Lagrange 或Newton 多项式进行比较。
三、实验要求:1.分别用内部函数和编程实现。
2.可以自拟实验题,要求同上。
四、实验程序及结果:方法一:内部函数法函数:Interpolation InterpolatingPolynomialTable[t[i]=i,{i,1,8}];Table[f[i]=Sin[t[i]]/t[i],{i,1,8}];Data=Table[{t[i],f[i]},{i,1,8}];a0=Interpolation[Data,InterpolationOrder 1];a1=InterpolatingPolynomial[Data,x]//Expand;c0=Plot[a0[x],{x,1,8},PlotStyle {Black,Thick},Frame True];c1=Plot[a1,{x,1,8},PlotStyle {Red,Thick},Frame True];b=Graphics[{PointSize[0.02],Black,Point[Data]}];d=Table[Plot[Evaluate[Sin[x]/x],{x,t[i],t[i+1]},PlotStyle {Blue,Thickness[0.001]}],{i,1,7}];Print["被插函数(蓝)、7次多项式差值(红)与分段线性差值(黑)如下图:"] Show[b,c1,c0,d,AspectRatio 2/3,Frame True]被插函数(蓝)、7次多项式差值(红)与分段线性差值(黑)如下图:方法二:编程实现法h[i_]:=t[i+1]-t[i];θ[x_,i_]:=(x-t[i])/h[i];Table[t[i]=i,{i,1,8}];l[x_,n_,xi_,xj_]:=Product[(x-xi)[[i]],{i,1,n}]/Product[(xj-xi)[[i]],{i,1,n}];L8[x_]:=l[x,7,{t[2],t[3],t[4],t[5],t[6],t[7],t[8]},t[1]]*f[1]+l[x,7,{t[1],t[3],t[4],t[5],t[6],t[7],t [8]},t[2]]*f[2]+l[x,7,{t[1],t[2],t[4],t[5],t[6],t[7],t[8]},t[3]]*f[3]+l[x,7,{t[1],t[2],t[3],t[5],t[6 ],t[7],t[8]},t[4]]*f[4]+l[x,7,{t[1],t[2],t[3],t[4],t[6],t[7],t[8]},t[5]]*f[5]+l[x,7,{t[1],t[2],t[3],t [4],t[5],t[7],t[8]},t[6]]*f[6]+l[x,7,{t[1],t[2],t[3],t[4],t[5],t[6],t[8]},t[7]]*f[7]+l[x,7,{t[1],t[2 ],t[3],t[4],t[5],t[6],t[7]},t[8]]*f[8];PL[x_,i_]:=f[i](1-θ[x,i])+f[i+1]θ[x,i];Table[f[i]=Sin[t[i]]/t[i],{i,1,8}];f[x_]:=Sin[x]/x;s1=Table[fig[i]=Plot[Evaluate[(PL[x,i]-Sin[x]/x)],{x,t[i],t[i+1]},PlotStyle →{Thickness[0.005],Blue}],{i,1,7}];s2=Table[fig[i]=Plot[Evaluate[L8[x]-Sin[x]/x],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.00 5],Red}],{i,1,7}];k=Table[fig[i]=Plot[Evaluate[PL[x,i]],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.005],Black }],{i,1,7}];g=Table[fig[i]=Plot[Evaluate[L8[x]],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.005],Red}], {i,1,7}];s=Table[fig[i]=Plot[Evaluate[Sin[x]/x],{x,t[i],t[i+1]},PlotStyle→{Blue,Thickness[0.015] }],{i,1,7}];Show[s,g,k,Axes→False,PlotRange→All,Frame→True]Show[s1,s2,Axes→False,PlotRange→All,Frame→True]h[i_]:=t[i+1]-t[i];θ[x_,i_]:=(x-t[i])/h[i];Table[t[i]=i,{i,1,8}];PH[x_,i_]:=f[i](2θ[x,i]^3-3θ[x,i]^2+1)+d[i]h[i](θ[x,i]^3-2θ[x,i]^2+θ[x,i])+(θ[x,i]^3-θ[x,i ]^2)h[i]d[i+1]+f[i+1](-2θ[x,i]^3+3θ[x,i]^2);PL[x_,i_]:=f[i](1-θ[x,i])+f[i+1] θ[x,i];Table[f[i]=Sin[t[i]]/t[i],{i,1,8}];f[x_]:=Sin[x]/x;Table[d[i]=(t[i]*Cos[t[i]]-Sin[t[i]])/t[i]^2,{i,1,8}];s1=Table[Plot[Evaluate[(PL[x,i]-Sin[x]/x)],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.005], Black}],{i,1,7}];s2=Table[Plot[Evaluate[PH[x,i]-Sin[x]/x],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.005],G reen}],{i,1,7}];k=Table[Plot[Evaluate[PL[x,i]],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.005],Black}],{i,1, 7}];g=Table[Plot[Evaluate[PH[x,i]],{x,t[i],t[i+1]},PlotStyle→{Thickness[0.006],Green}],{i,1 ,7}];s=Table[Plot[Evaluate[Sin[x]/x],{x,t[i],t[i+1]},PlotStyle→{Blue,Thickness[0.003]}],{i,1, 7}];Show[g,k,s,Axes→False,PlotRange→All,Frame→True]Show[s1,s2,Axes→False,PlotRange→All,Frame→True]五、实验总结:通过本次实验我加深了对分段线性插值、Hermite多项式插值、拉格朗日插值和牛顿插值的了解,也知道了这几种插值方法的优缺点。
数值分析课后答案(4)习题四1.已知ln(2.0)=0.6931;ln(2.2)=0.7885,ln(2.3)=0.8329, 试用线性插值和抛物插值计算.ln2.1的值并估计误差解:线形插值:取02.0x = 00.6931y = 12.2x = 10.7885y = 22.3x = 20.8329y = 110 2.1 2.3 2.1 2.0(0)(1)0.69310.832901102.0 2.32.3 2.0x x x x L f x f x x x x x ----=+=+----=0.7410抛物线插值:12200102()()()()x x x x l x x x x --=-- 02211012()()()()x x x x l x x x x --=-- 01222021()()()()x x x x l x x x x --=--2200211222L l y l y l y =++=0.7422.已知x=0,2,3,5对应的函数值分别为y=1,3,2,5.试求三次多项式的插值解:解:取00x = 12x = 23x = 35x = 12330010203()()()()()()x x x x x x l x x x x x x ---=--- 023********()()()()()()x x x x x x l x x x x x x ---=---01332202123()()()()()()x x x x x x l x x x x x x ---=--- 01233303132()()()()()()x x x x x x l x x x x x x ---=---3300311322333L l y l y l y l y =+++=1156261310323++-x x x3.设函数f(x)在[a,b]上具有直到二阶的连续导数,且f(a)=f(b)=0, 求证:2"1m ax |()|()m ax |()|8a x ba x bf x b a f x ≤≤≤≤≤-解:取01;x a x b ==,1()()0x a x b L f a f b a bb a--=+=--''''211()()()|()()||()()|||||224f f b a R f x L x x a x b εε-=-≤--≤∴''21()()|()||()|||||24f b a f x L x ε-≤+''1()|()||||()|8f L x b a ε=+-|||8)("|a b f -=ε4.证明n 次Lagrange 插值多项式基函数满足∑==ni ki n ki x x l x 0,)(, n k ≤≤0解:取()kf x x = 则n 0()nki i Ln lx x ==∑(1)()()()!n nii fx f x Ln Rn x x n +=-==-∑(1)0()()!k n nii x x x n +==-∑=0所以()()f x Ln x = 即证 5.证明 )(')()()(,xi x x x x l n i n i n ωω-=证明:、01110111()()()()()ln ()()()()()i i n i i i i i i i n x x x x x x x x x x i x x x x x x x x x x -+-+-----= -----01110111()()()()()()()()()()i i ni i ii i i i i nix x x x x x x x x x x x x x x x x x x x x x x x -+-+------=------取 0111()()()()()()n i ii n x x xx xxxx x x x x ω-+=------则 '1020111011()()()())()()()()()()()()()n nn i in n x x x x x x x x x x x x x xx xx x x x x x x x x xxω-+-=--+---+-----++--- ('0111()()()()()()n i i i i i i i i n x x x x x x x x x x x ω-+=-----所以,'()ln ()()n i n i x i x x x ωω=-6.设nn x a x a a x f ++=10)(有n 个不同的实根.,,21n x x x证明:=-=∑11,0)('n ni i kia x f x证明:取()kx x ?= 1()()n n x x xx ω=-- 而,0()nn f x a a x =++ 有n 个不同的实根。