matlab数值分析程序--高等数学,数值代数的matlab实现-文字版, matlab电子书, 和matlab 有关的电子书:

6.2.3 n次拉格朗日(Lagrange)插值及其MATLAB程序

6.2.3  n次拉格朗日(Lagrange)插值及其MATLAB程序

 

例6.2.4  给出节点数据,作三次拉格朗日插值多项式计算,并估计其误差.

解  输入程序

>>  X=[-2,0,1,2]; Y =[17,1,2,17];

p1=poly(X(1)); p2=poly(X(2));

p3=poly(X(3)); p4=poly(X(4));

l01= conv ( conv (p2, p3), p4)/(( X(1)- X(2))* ( X(1)- X(3)) * ( X(1)- X(4))),

l11= conv ( conv (p1, p3), p4)/(( X(2)- X(1))* ( X(2)- X(3)) * ( X(2)- X(4))),

l21= conv ( conv (p1, p2), p4)/(( X(3)- X(1))* ( X(3)- X(2)) * ( X(3)- X(4))),

l31= conv ( conv (p1, p2), p3)/(( X(4)- X(1))* ( X(4)- X(2)) * ( X(4)- X(3))),

l0=poly2sym (l01),

l1=poly2sym (l11),l2=poly2sym (l21), l3=poly2sym (l31),

P = l01* Y(1)+ l11* Y(2) + l21* Y(3) + l31* Y(4),

运行后输出基函数l0,l1,l2和l3及其插值多项式的系数向量P(略)为

l0 =

-1/24*x^3+1/8*x^2-1/12*x,l1 =1/4*x^3-1/4*x^2-x+1

l2 =

-1/3*x^3+4/3*x,l3 =1/8*x^3+1/8*x^2-1/4*x

输入程序

>>  L=poly2sym (P),x=0.6; Y = polyval(P,x)

运行后输出插值多项式和插值为

L =                        Y =

x^3+4*x^2-4*x+1            0.2560.

输入程序

>> syms M; x=0.6;

R3=M*abs((x-X(1))*(x-X(2)) *(x-X(3)) *(x-X(4)))/24

运行后输出误差限为

R3 =

91/2500*M

即         

R3 ,     .

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/3/3060203.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1