ColoState Notes on the Simpson’s Quadrature MATH451 Jiangguo (James) Liu

advertisement
ColoState
MATH451
Notes on the Simpson’s Quadrature
Jiangguo (James) Liu
∗
February 13, 2016
Actually we examine the composite Simpson’s quadrature. Assuming the interval [a, b] is uniformly partitioned into n = 2m small intervals with length h = (b − a)/n. Two small intervals
are combined to apply the simple-version Simpson’s quadrature, for which the “interval” length
is 2h and the weights 61 , 46 , 16 sum to 1. The composite Simpson’s quadrature is mathematically
formulated as
!
Z b
m
m−1
X
X
h
f (x0 ) + 4
f (x)dx ≈
f (x2i−1 ) + 2
f (x2i ) + f (x2m ) .
3
a
i=1
i=1
However, in Matlab, index starts from 1. As shown in the sample code below,
• f (x0 ) is represented by y(1),
• f (x2i−1 ) is represented by y(2*i),
Pm
•
i=1 f (x2i−1 ) actually becomes sum(y(2:2:2*m)).
Here is the Matlab code for the composite Simpson’s quadrature:
function NumerIntgrl = QuadratureSimpson(fxnf,a,b,n)
m = n/2; h = (b-a)/n; x = a:h:b;
y = fxnf(x); % Evaluation at all nodes "simultaneously"
SO = sum(y(2:2:2*m)); % Sum of all odd terms
SE = sum(y(3:2:2*m-1)); % Sum of the even terms in the middle
NumerIntgrl = (h/3) * (y(1) + 2*SE + 4*SO + y(2*m+1)); % All together
return;
Here are some numerical results.
Table 1: The composite Simpson’s quadrature applied to
# of partitions
Approx. value
Error
32 1.000000041706364 -4.170636414002615e-08
64 1.000000002606974 -2.606973970031845e-09
128 1.000000000162941 -1.629407719860865e-10
256 1.000000000010184 -1.018385376028164e-11
512 1.000000000000636 -6.363798377151397e-13
1024 1.000000000000040 -3.952393967665557e-14
R1
0
xex dx = 1
Error reduction
N/A
15.99
15.99
15.99
16.00
16.10
The error reduction ratio 16 verifies the truncation error O(h4 ).
∗
Department of Mathematics,
(liu@math.colostate.edu)
Colorado
State
University,
1
Fort
Collins,
CO 80523-1874,
USA
Download