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

6.2.2 抛物线插值及其MATLAB程序

6.2.2  抛物线插值及其MATLAB程序

 

例6.2.3  求将区间 [0, π/2] 分成等份,用产生个节点,然后根据(6.9)和(6.13)式分别作线性插值函数和抛物线插值函数.用它们分别计算cos (π/6) (取四位有效数字),并估计其误差.

解  输入程序

>> X=[0,pi/2]; Y =cos(X) ,

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=pi/6;

Y = polyval(P,x)

运行后输出基函数l0和l1及其插值多项式的系数向量P、插值多项式和插值为

l0 =

-5734161139222659/9007199254740992*x+1

l1 =

5734161139222659/9007199254740992*x

P =

  -0.6366    1.0000

L =

-5734161139222659/9007199254740992*x+1

Y =

0.6667

输入程序

>> M=1;x=pi/6; R1=M*abs((x-X(1))*(x-X(2)))/2

运行后输出误差限为

R1 =

0.2742.

(2) 输入程序

>> X=0:pi/4:pi/2; Y =cos(X) ,

l01= conv (poly(X(2)),

poly(X(3)))/(( X(1)- X(2))* ( X(1)- X(3))),

l11= conv (poly(X(1)),

poly(X(3)))/(( X(2)- X(1))* ( X(2)- X(3))),

l21= conv (poly(X(1)),

poly(X(2)))/(( X(3)- X(1))* ( X(3)- X(2))),

l0=poly2sym (l01),l1=poly2sym (l11),l2=poly2sym (l21),

P = l01* Y(1)+ l11* Y(2) + l21* Y(3), L=poly2sym (P),x=pi/6; Y = polyval(P,x)

运行后输出基函数l01、l11和l21及其插值多项式的系数向量P、插值多项式L和插值Y为

l0 =

228155022448185/281474976710656*x^2-2150310427208497/1125899906842624*x+1

l1 =

-228155022448185/140737488355328*x^2+5734161139222659/2251799813685248*x

l2 =

228155022448185/281474976710656*x^2-5734161139222659/9007199254740992*x

P =

  -0.3357   -0.1092    1.0000

L=

-6048313895780875/18014398509481984*x^2-7870612110600739/72057594037927936*x+1

Y =

 0.8508

输入程序

>> M=1;x=pi/6; R2=M*abs((x-X(1))*(x-X(2)) *(x-X(3)))/6

运行后输出误差限为

R2 =

0.0239.

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