Professional Documents
Culture Documents
May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.
5
Numerical Integration
5.1 Introduction
The definite integral
b
I+ f / Ã f +x/ Å x (5.1)
a
is defined in calculus as a limit of what are called Riemann sums. It is then proven that
I+ f / F+b/ F+a/ (5.2)
where F+x/ is any antiderivative of f +x/; this is the Fundamental Theorem of Calculus. Many integrals
can be evaluated by using this formula, and a significant portion of most calculus textbooks is devoted
to this approach. Nonetheless, most integrals cannot be evaluated by using (5.2) because most
integrands f +x/ do not have antiderivatives expressible in terms of elementary functions. Examples of
such integrals are
1 S
x 2
S
Ã Æ Åx à x sin, x 0 Å x (5.3)
0 0
Copyright @ 2010. De Gruyter Oldenbourg.
In the first section of this chapter, we define two of the oldest and most popular numerical methods for
approximating integrals like (5.1): the trapezoidal rule and Simpson's rule. We also analyze the error in
using these methods and then obtain improvements on them. A third method is Gaussian quadrature
which will be discussed in addition to the two methods stated. This method is more complicated in its
origin than Simpson's and the trapezoidal method, but it is almost always much superior in accuracy for
similar amounts of computation.
is to replace f +x/ by an approximating function whose integral can be evaluated. In this section, we will
look at methods based on linear and quadratic interpolation.
y f#x'
p1+x/
Copyright @ 2010. De Gruyter Oldenbourg.
a b
f +a/ f +b/
T1 + f / +b a/ . (5.6)
2
This approximates the integral I+ f / if f +x/ is almost linear on #a, b'.
Example 5.1. Trapezoidal Method I
Approximate the integral
1 1
I Ã Åx (5.7)
0 1x
Solution 5.1. The true value of this integral is
1 1
I0 Ã Åx
0 x1
log+2/
The approximation is exact in the first digit on the right hand side of the radix point.Ô
To improve the approximation T1 + f / in (5.4) when f +x/ is not a nearly linear function on #a, b', break
the interval #a, b' into smaller subintervals and apply (5.5) on each subinterval. If the subintervals are
small enough, then f +x/ will be nearly linear on each one. This idea is illustrated in Figure 5.2:
Copyright @ 2010. De Gruyter Oldenbourg.
172 Mathematics for Engineers
All rights reserved. May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.
y f+x/
p1+x/
x0 x1 x2
a b
3 4
log log
2 3
Copyright @ 2010. De Gruyter Oldenbourg.
1 1 1 1 1 1
T2 0 f +0/ f 1 f +1/ f
2 2 2 2 2 2
17
24
Approximate each subinterval by using a linear interpolating polynomial such as (5.5) and noting that
each subinterval #xi , xi1 ' has length h. Then
n1 n2
h 1 1
Tn + f / Å + f +xi / f +xi1 // h f +x0 / f +xn / Å f +xi / . (5.12)
i 0
2 2 2 i 1
This is called the trapezoidal numerical integration rule. The subscript n gives the number of
subintervals being used; and the points x0 , x1 , …, xn are called the numerical integration node points.
The following lines show an implementation of the trapezoidal method in a few steps using formula
(5.12). The implementation is straight forward and does not use special features of the evaluation.
Copyright @ 2010. De Gruyter Oldenbourg.
174 Mathematics for Engineers
All rights reserved. May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.
x2 Æx
2
The following line is an application of the function trapezoidalMethod to the function f +x/
0.18932
Before giving some numerical examples of Tn + f /, we would like to discuss the choice of n. With a
sequence of increasing values of n, Tn + f / will usually be an increasingly accurate approximation of
I+ f /. But which sequence of values of n should be used? If n is doubled repeatedly, then the function
values used in each T2 n + f / will include all of the earlier function values used in the preceding Tn + f /.
Thus, the doubling of n will ensure that all previously computed information is used in the new
calculation, making the trapezoidal rule less expensive than it would be otherwise. To illustrate how
function values are reduced when n is doubled, consider T2 + f / and T4 + f /.
f +x0 / f +x2 / ba ab
T2 + f / h f +x1 / with h , x0 a, x1 , x2 b. (5.13)
2 2 2 2
Also
f +x0 / f +x4 / ba
T4 + f / h f +x1 / f +x2 / f +x3 / with h ,
Copyright @ 2010. De Gruyter Oldenbourg.
2 2 4
(5.14)
3ab ab a3b
x0 a, x1 , x2 , x3 , x4 b.
4 2 4
Comparing the two approximations, we observe that f +x1 / and f +x3 / need to be evaluated, as the other
function values are known from the lower approximation. For this and other reasons, all of our
examples of Tn + f / are based on doubling n.
IV - Chapter 5: Numerical Integration 175
All rights reserved. May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.
for the interval #0, 2 S'. The number of iterations are n 2, 4, 8, 16, 32, 64, 128, 256.
Solution 5.3. The exact values for these functions can be determined by using the antiderivatives
of the functions
1
I1 Ã f +x/ Å x
0
1
S erf+1/
2
4
I2 Ã g+x/ Å x
0
1
tan +4/
and
2S
I3 Ã h+x/ Å x
0
2S
The approximation for the different functions and different iteration numbers follow from the lines
below
Copyright @ 2010. De Gruyter Oldenbourg.
Tf +trapezoidalMethod+ f +x/, x, 0, 1, Ó1/ &/ s 2, 4, 8, 16, 32, 64, 128, 256
Tg +trapezoidalMethod+g+x/, x, 0, 4, Ó1/ &/ s 2, 4, 8, 16, 32, 64, 128, 256
Th +trapezoidalMethod+h+x/, x, 0, 2 S, Ó1/ &/ s 2, 4, 8, 16, 32, 64, 128, 256
The errors with respect to the exact value of the integrals are
H1 I1 Tf
0.0154539, 0.00384004, 0.000958518, 0.000239536,
0.0000598782, 0.0000149692, 3.74227 106 , 9.35566 107
H2 I2 Tg
H3 I3 Th
0.561191, 0.0375927, 0.000192788,
5.12258 109 , 8.88178 1016 , 8.88178 1016 , 0., 8.88178 1016
These data are collected in the following table for each integral and each number of used interpola-
tion steps.
TableForm$Prepend$2, 4, 8, 16, 32, 64, 128, 256, H1, H2, H3¬ , n, "H1", "H2", "H3"((
n H1 H2 H3
2 0.0154539 0.133006 0.561191
4 0.00384004 0.0035941 0.0375927
8 0.000958518 0.000564261 0.000192788
16 0.000239536 0.000144082 5.12258 109
32 0.0000598782 0.000036038 8.88178 1016
6
64 0.0000149692 9.01059 10 8.88178 1016
128 3.74227 106 2.25272 106 0.
256 9.35566 107 5.63183 107 8.88178 1016
From the table it is obvious that the error decreases with increasing n. The third example converges
very rapidly.Ô
Copyright @ 2010. De Gruyter Oldenbourg.
b
I+ f / Ã p2 +x/ Å x
a
(5.15)
b +x c/ +x b/ +x a/ +x b/ +x a/ +x c/
à f +a/ f +c/ f +b/! Šx.
a +a c/ +a b/ +c a/ +c b/ +b a/ +b c/
This integral can be evaluated directly, but it is easier to first introduce h +b a/ s 2 and then change
the variable of integration. We will evaluate the first term to illustrate the general procedure. Let
u x a. Then
+x b/ +x c/
t1 Simplify% s. b a 2 h, c a h)
+a b/ +a c/
+a h x/ +a 2 h x/
2 h2
t2 t1 s. x a u
+h u/ +2 h u/
2 h2
b +x c/ +x b/ a2 h
à Åx à +x c/ +x b/ Å x
a +a c/ +a b/ a
(5.16)
1 2h 1 u3 3 h
à +u h/ +u 2 h/ Šu u h 2 h u!
2 2 2h
0 .
2 h2 0 2 h2 3 2 3
The complete evaluation of (5.15) yields
h ab
S2 + f / % f +a/ 4 f f +b/). (5.17)
3 2
The method is illustrated in Figure 5.3:
Copyright @ 2010. De Gruyter Oldenbourg.
178 Mathematics for Engineers
All rights reserved. May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.
The symbolic derivation of his formula takes the same steps as discussed above. First define the
polynomial
E+a/ ++x b/ +x c// E+b/ ++x a/ +x c// E+c/ ++x a/ +x b//
p2+x_/ :
+a b/ +a c/ +b a/ +b c/ +c a/ +c b/
N#H0'
0.00129726
To compare this with the trapezoidal rule, use T2 , since the number of function evaluation is the
same for both S2 and T2 by a factor of about 11, a significant increase in accuracy
N#T2 S2'
0.0138889
T2 S2
N% )
H0
10.7063
Copyright @ 2010. De Gruyter Oldenbourg.
Follow the ideas as stated for the trapezoidal method to introduce subintervals into the interval
#a, b' #x0 , xn '. The intervals should be not too small and containing three interpolation points. Thus,
b xn n1 xi1
I+ f / à f +x/ Å x à f +x/ Å x Åà f +x/ Å x (5.20)
a x0 i 0 xi
0.882081
IV - Chapter 5: Numerical Integration 181
All rights reserved. May not be reproduced in any form without permission from the publisher, except fair uses permitted under U.S. or applicable copyright law.
for the interval #0, 2 S'. The number of iterations are n 2, 4, 8, 16, 32, 64, 128, 256.
Solution 5.5. The exact values for these functions can be determined by using the antiderivatives
of the functions
1
I1 Ã f +x/ Å x
0
1
S erf+1/
2
4
I2 Ã g+x/ Å x
0
1
tan +4/
and
2S
I3 Ã e+x/ Å x
0
2S
The approximation for the different functions and different iteration numbers follow from the lines
below
Sf +simpsonMethod+ f +x/, x, 0, 1, Ó1/ &/ s 2, 4, 8, 16, 32, 64, 128, 256
Copyright @ 2010. De Gruyter Oldenbourg.
Sg +simpsonMethod+g+x/, x, 0, 4, Ó1/ &/ s 2, 4, 8, 16, 32, 64, 128, 256
Se +simpsonMethod+e+x/, x, 0, 2 S, Ó1/ &/ s 2, 4, 8, 16, 32, 64, 128, 256