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

9.4.2 龙贝格积分的MATLAB程序

9.4.2  龙贝格积分的MATLAB程序

龙贝格数值积分的MATLAB主程序

function [RT,R,wugu,h]=romberg(fun,a,b, wucha,m)

n=1;h=b-a; wugu=1; x=a;k=0; RT=zeros(4,4);

RT(1,1)=h*(feval(fun,a)+feval(fun,b))/2;

while((wugu>wucha)&(k<m)|(k<4))

          k=k+1;   h=h/2; s=0;

           for j=1:n

             x=a+h*(2*j-1); s=s+feval(fun,x);

end

RT(k+1,1)= RT(k,1)/2+h*s; n=2*n;

for i=1:k

RT(k+1,i+1)=((4^i)*RT(k+1,i)-RT(k,i))/(4^i-1);

end

wugu=abs(RT(k+1,k)-RT(k+1,k+1));

end

R=RT(k+1,k+1);

 

例9.4.2  取精度为,分别用作为计算停止的条件,用romberg.m程序计算d,龙贝格积分表,最小步长h,取精度为,并与精确值比较.然后取精度为,用作为计算停止的条件,观察用龙贝格求积公式计算的结果与精确值的绝对误差是否满足.

解 (1)取精度分别为,当用作为计算停止的条件,输入程序

>>F=inline('1./(1+x)'); [RT,R,wugu,h]=romberg(F,0,1.5,1.e-8,13)

syms x

fi=int(1/(1+x),x,0,1.5); Fs=double(fi),

wR=double(abs(fi-R)), wR1= wR - wugu

运行后屏幕显示精确值Fs,取精度为,利用龙贝格求积公式的romberg.m程序计算的近似值R,龙贝格积分表RT,误差估计err,最小步长h,近似值R与精确值Fs的绝对误差wR如下

RT = 

Columns 1 through 4

1.05000000000000                 0                  0                  0

0.95357142857143  0.92142857142857                  0                 0

0.92598357524828  0.91678762414057  0.91647822765470                 0

0.91874179909571  0.91632787371152  0.91629722368292  0.9162943506040

0.91690534165717  0.91629318917766  0.91629087687540  0.91629077613242

0.91644450130657  0.91629088785636  0.91629073443494  0.91629073217398

             Columns 5 through 6

                   0                  0

                   0                  0

                   0                  0

                   0                  0

  0.91629076211489                0

  0.91629073200160   0.91629073197216

R =                 wugu =                        h =

    0.91629073197216       2.943623123030648e-011      0.04687500000000

Fs =                  wR =                       wR1 =

     0.91629073187416      9.800686628988125e-011     6.857063505957478e-011

 

如果用作为计算停止的条件,运行的结果如下

RT = 

Columns 1 through 4

       1.05000000000000                  0                  0                  0

        0.95357142857143   0.92142857142857                  0                  0

          0.92598357524828   0.91678762414057   0.91647822765470                  0

   0.91874179909571   0.91632787371152   0.91629722368292   0.91629435060401

   0.91690534165717   0.91629318917766   0.91629087687540   0.91629077613242

   0.91644450130657   0.91629088785636   0.91629073443494   0.91629073217398

   0.91632918157305   0.91629074166188   0.91629073191558   0.91629073187559

           Columns 5 through 7

                  0                  0                  0

                  0                  0                  0

                  0                  0                  0

                  0                  0                  0

   0.91629076211489                 0                  0

   0.91629073200160   0.91629073197216                0

   0.91629073187442   0.91629073187429   0.91629073187427

R =                 wugu =                      h =

0.91629073187427       9.789258292869363e-011     0.02343750000000

wR =                        wR1 =

1.142833611876187e-013        -9.777829956750600e-011

 

(2)取精度分别为,当用作为计算停止的条件,计算结果如下

RT = 

Columns 1 through 4

1.05000000000000                 0                 0                  0

                  0

                  0

                  0

   0.91629076211489

R =                    wugu =                     h =

0.91629076211489        1.401753557672691e-008    0.09375000000000

Fs =                    wR =                   wR1 =

0.91629073187416      3.024073362534249e-008   1.622319804861558e-008

由此可见,取精度为,用作为计算停止的条件,用龙贝格求积公式计算的结果与精确值的绝对误差满足.

 

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