Page 241 - Applied Numerical Methods Using MATLAB
P. 241
230 NUMERICAL DIFFERENTIATION/ INTEGRATION
estimate of the integral. This sequential procedure of Romberg integration is cast
into the MATLAB routine “rmbrg()”.
Before closing this section, we test and compare the trapezoidal method
(“trpzds()”), Simpson method (“smpsns()”), and Romberg integration
(“rmbrg()”) by trying them on the following integral
4 4 4
400x(1 − x)e −2x dx = 100 −2e −2x x(1 − x) + 2e −2x (1 − 2x) dx
0 0 0
4 4
4
= 100 −2e −2x x(1 − x) − e −2x (1 − 2x) − 2 e −2x dx
0 0
0
4
= 200x e = 3200e −8 = 1.07348040929 (5.7.5)
2 −2x
0
Here are the MATLAB statements for this job listed together with the run-
ning results.
>>f = inline(’400*x.*(1 - x).*exp(-2*x)’,’x’);
>>a=0;b=4;N=80;
>>format short e
>>true_I = 3200*exp(-8)
>>It = trpzds(f,a,b,N), errt = It-true_I %trapezoidal
It = 9.9071e-001, errt = -8.2775e-002
>>Is = smpsns(f,a,b,N), errs = Is-true I %Simpson
INTfs = 1.0731e+000, error = -3.3223e-004
>>[IR,R,err,N1] = rmbrg(f,a,b,.0005), errR = IR - true I %Romberg
INTfr = 1.0734e+000, N1 = 32
error = -3.4943e-005
As expected from the fact that the errors of numerical integration by the trape-
4
2
zoidal method and Simpson method are O(h ) and O(h ), respectively, the
Simpson method presents better results (with smaller error) than the trapezoidal