2 Integration
2 Integration
We want to construct numerical algorithms that can perform definite integrals of the form
b
I =∫ f (x)dx.
a
Calculating these definite integrals numerically is called numerical integration, numerical quadrature, or more simply quadrature.
Elementary formulas
We first consider integration from 0 to h , with h small, to serve as the building blocks for integration over larger domains. We here
define I as the following integral:
h
Ih = ∫ f (x)dx.
0
To perform this integral, we consider a Taylor series expansion of f (x) about the value x = h/2 :
2
(x − h/2)
′ ′′
f (x) = f (h/2) + (x − h/2)f (h/2) + f (h/2)
2
3 4
(x − h/2) (x − h/2)
′′′ ′′′′
+ f (h/2) + f (h/2) + …
6 24
Midpoint rule
The midpoint rule makes use of only the first term in the Taylor series expansion. Here, we will determine the error in this
approximation. Integrating,
h 2
(x − h/2)
′ ′′
Ih = hf (h/2) + ∫ ((x− h/2)f (h/2) + f (h/2)
0
2
3 4
(x − h/2) (x − h/2)
′′′ ′′′′
+ f (h/2) + f (h/2) + …) dx.
6 24
Changing variables by letting y = x − h/2 and dy = dx , and simplifying the integral depending on whether the integrand is even
or odd, we have
Ih =hf (h/2)
h/2 2 3 4
y y y
′ ′′ ′′′ ′′′′
+∫ (y f (h/2) + f (h/2) + f (h/2) + f (h/2) + …) dy
−h/2 2 6 24
h/2 4
y
2 ′′ ′′′′
= hf (h/2) + ∫ (y f (h/2) + f (h/2) + …) dy.
0
12
Therefore,
3 5
h ′′
h ′′′′
Ih = hf (h/2) + f (h/2) + f (h/2) + …
24 1920
Trapezoidal rule
From the Taylor series expansion of f (x) about x = h/2 , we have
2 3 4
h h h h
′ ′′ ′′′ ′′′′
f (0) = f (h/2) − f (h/2) + f (h/2) − f (h/2) + f (h/2) + … ,
2 8 48 384
and
3.1 https://math.libretexts.org/@go/page/93742
2 3 4
h ′
h ′′
h ′′′
h ′′′′
f (h) = f (h/2) + f (h/2) + f (h/2) + f (h/2) + f (h/2) + … .
2 8 48 384
We now substitute for the first term on the right-hand-side using the midpoint rule formula:
3 5
h h ′′
h ′′′′
(f (0) + f (h)) = ( Ih − f (h/2) − f (h/2))
2 24 1920
3 5
h h
′′ ′′′′
+ f (h/2) + f (h/2) + … ,
8 384
3 5
h h h
′′ ′′′′
Ih = (f (0) + f (h)) − f (h/2) − f (h/2) + …
2 12 480
Simpson’s rule
To obtain Simpson’s rule, we combine the midpoint and trapezoidal rule to eliminate the error term proportional to h . Multiplying 3
or
5
h h
′′′′
Ih = (f (0) + 4f (h/2) + f (h)) − f (h/2) + … .
6 2880
Usually, Simpson’s rule is written by considering the three consecutive points 0, h and 2h . Substituting h → 2h , we obtain the
standard result
5
h h
′′′′
I2h = (f (0) + 4f (h) + f (2h)) − f (h) + …
3 90
Composite rules
We now use our elementary formulas obtained for (3.2) to perform the integral given by (3.1).
Trapezoidal rule
We suppose that the function f (x) is known at the n + 1 points labeled as x 0, x1 , … , xn , with the endpoints given by x 0 =a and
x = b . Define
n
fi = f (xi ) , hi = xi+1 − xi .
∫ f (x)dx = ∑ ∫ f (x)dx
a xi
i=0
n−1 hi
= ∑∫ f (xi + s) ds,
i=0 0
where the last equality arises from the change-of-variables s = x − x . Applying the trapezoidal rule to the integral, we have
i
b n−1
1
∫ f (x)dx = ∑ hi (fi + fi+1 ) .
a
2
i=0
If the points are not evenly spaced, say because the data are experimental values, then the hi may differ for each value of i and
(3.13) is to be used directly.
3.2 https://math.libretexts.org/@go/page/93742
However, if the points are evenly spaced, say because f (x) can be computed, we have hi = h , independent of i. We can then
define
xi = a + ih, i = 0, 1, … , n;
The composite trapezoidal rule for evenly space points then becomes
b n−1
h
∫ f (x)dx = ∑ (fi + fi+1 )
a
2
i=0
h
= (f0 + 2 f1 + ⋯ + 2 fn−1 + fn ) . (3.1)
2
The first and last terms have a multiple of one; all other terms have a multiple of two; and the entire sum is multiplied by h/2
Simpson’s rule
We here consider the composite Simpson’s rule for evenly space points. We apply Simpson’s rule over intervals of 2h , starting
from a and ending at b :
b
h h
∫ f (x)dx = (f0 + 4 f1 + f2 ) + (f2 + 4 f3 + f4 ) + …
a
3 3
h
+ (fn−2 + 4 fn−1 + fn ) .
3
Note that n must be even for this scheme to work. Combining terms, we have
b
h
∫ f (x)dx = (f0 + 4 f1 + 2 f2 + 4 f3 + 2 f4 + ⋯ + 4 fn−1 + fn ) .
a
3
The first and last terms have a multiple of one; the even indexed terms have a multiple of 2; the odd indexed terms have a multiple
of 4 ; and the entire sum is multiplied by h/3.
Adaptive integration
The useful MATLAB function quad.m performs numerical integration using adaptive Simpson quadrature. The idea is to let the
computation itself decide on the grid size required to achieve a certain level of accuracy. Moreover, the grid size need not be the
same over the entire region of integration.
We begin the adaptive integration at what is called Level 1. The uniformly spaced points at which the function f (x) is to be
evaluated are shown in Fig. 3.1. The distance between the points a and b is taken to be 2h, so that
b −a
h = .
2
Integration using Simpson’s rule (3.11) with grid size h yields for the integral I ,
5
h h ′′′′
I = (f (a) + 4f (c) + f (b)) − f (ξ),
3 90
where ξ is some value satisfying a ≤ ξ ≤ b . Integration using Simpson’s rule twice with grid size h/2 yields
5 5
h (h/2) (h/2)
′′′′ ′′′′
I = (f (a) + 4f (d) + 2f (c) + 4f (e) + f (b)) − f (ξl ) − f (ξr ) ,
6 90 90
3.3 https://math.libretexts.org/@go/page/93742
with ξ and ξ some values satisfying a ≤ ξ
l r l ≤c and c ≤ ξ r ≤b .
We now define the two approximations to the integral by
h
S1 = (f (a) + 4f (c) + f (b)),
3
h
S2 = (f (a) + 4f (d) + 2f (c) + 4f (e) + f (b)),
6
We now ask whether the value of S for the integral is accurate enough, or must we further refine the calculation and go to Level
2
2? To answer this question, we make the simplifying approximation that all of the fourth-order derivatives of f (x) in the error
terms are equal; that is,
′′′′ ′′′′ ′′′′
f (ξ) = f (ξl ) = f (ξr ) = C .
Then
5
h
E1 = − C,
90
5
h 1
E2 = − C = E1 .
4
2 ⋅ 90 16
Now since the integral is equal to the approximation plus its associated error,
S1 + E1 = S2 + E2 ,
and since
E1 = 16 E2 ,
1
E2 = (S2 − S1 ) .
15
then we can accept S as I . If the error estimate is larger in magnitude than tol, then we proceed to Level 2 . The computation at
2
Level 2 further divides the integration interval from a to b into the two integration intervals a to c and c to b , and proceeds with the
above procedure independently on both halves. Integration can be stopped on either half provided the tolerance is less than tol/2
(since the sum of both errors must be less than tol). Otherwise, either half can proceed to Level 3 , and so on.
As a side note, the two values of I given above (for integration with step size h and h/2) can be combined to give a more accurate
value for I given by
16 S2 − S1
7
I = + O (h ) ,
15
This page titled 3: Integration is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Jeffrey R. Chasnov via source
content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.
3.4 https://math.libretexts.org/@go/page/93742