7.6 Numerical Integration
7.6 Numerical Integration
6: Numerical Integration
Learning Objectives
Approximate the value of a definite integral by using the midpoint and trapezoidal rules.
Determine the absolute and relative error in using a numerical integration technique.
Estimate the absolute and relative error using an error-bound formula.
Recognize when the midpoint and trapezoidal rules over- or underestimate the true value of an integral.
Use Simpson’s rule to approximate the value of a definite integral to a given accuracy.
The antiderivatives of many functions either cannot be expressed or cannot be expressed easily in closed form (that is, in terms of known functions). Consequently, rather than evaluate
definite integrals of these functions directly, we resort to various techniques of numerical integration to approximate their values. In this section, we explore several of these
techniques. In addition, we examine the process of estimating the error in using these techniques.
may be viewed as an estimate of ∫ f (x) dx . Recall that a Riemann sum of a function f (x) over an interval [a, b] is obtained by selecting a partition
a
P = { x0 , x1 , x2 , … , xn }
and a set
∗ ∗ ∗
S = { x , x , … , xn }
1 2
where x i−1 ≤x
∗
i
≤ xi for all i.
The Riemann sum corresponding to the partition P and the set S is given by ∑ f (x ∗
i
)Δxi , where Δx i = xi − xi−1 , the length of the i
th
subinterval.
i=1
The midpoint rule for estimating a definite integral uses a Riemann sum with subintervals of equal width and the midpoints, m , of each subinterval in place of x . Formally, we state a i
∗
i
n
subinterval, set
n
Mn = ∑ f (mi )Δx.
i=1
As we can see in Figure 7.6.1, if f (x) ≥ 0 over [a, b], then ∑ f (m i )Δx corresponds to the sum of the areas of rectangles approximating the area between the graph of f (x) and the
i=1
x -axis over [a, b]. The graph shows the rectangles corresponding to M for a nonnegative function over a closed interval [a, b].
4
Figure 7.6.1 : The midpoint rule approximates the area between the graph of f (x) and the x -axis by summing the areas of rectangles with midpoints that are points on f (x).
1 −0 1
Solution: Each subinterval has length Δx = = . Therefore, the subintervals consist of
4 4
1 1 1 1 3 3
[0, ], [ , ], [ , ] , and [ , 1] .
4 4 2 2 4 4
8
,
3
8
,
5
8
,
7
8
}. Thus,
1 1 1 9 1 25 1 49
= ⋅ + ⋅ + ⋅ + ⋅
4 64 4 64 4 64 4 64
21
= = 0.328125.
64
Since
1
1
2
∫ x dx = ,
0
3
and we see that the midpoint rule produces an estimate that is somewhat close to the actual value of the definite integral.
2
x
2
on [1, 4].
Solution: The length of y = 1
2
2
x on [1, 4] is
−−−−−−−−−
4 2
dy
s =∫ √1 + ( ) dx.
1
dx
4
dy −−−− −
Since =x , this integral becomes ∫ 2
√1 + x dx.
dx 1
4 −1 1
If [1, 4] is divided into six subintervals, then each subinterval has length Δx = = and the midpoints of the subintervals are {
5
4
,
7
4
,
9
4
,
11
4
,
13
4
,
15
4
} . If we set
6 2
−−−− −
f (x) = √1 + x
2
,
1
5 1
7 1 9 1 11 1 13 1 15
M6 = ⋅f ( )+ ⋅f ( )+ ⋅f ( )+ ⋅f ( )+ ⋅f ( )+ ⋅f ( )
2 2
4 4 2 4 2 4 2 4 2 4
1
≈ (1.6008 + 2.0156 + 2.4622 + 2.9262 + 3.4004 + 3.8810) = 8.1431 units.
2
Exercise 7.6.1
2
1
Use the midpoint rule with n = 2 to estimate ∫ dx.
1
x
Hint
1 5 7
Δx = , m1 = , and m2 = .
2 4 4
Answer
24
≈ 0.685714
35
Figure 7.6.2 : Trapezoids may be used to approximate the area under a curve, hence approximating the definite integral.
The trapezoidal rule for estimating definite integrals uses trapezoids rather than rectangles to approximate the area under a curve. To gain insight into the final form of the rule,
consider the trapezoids shown in Figure 7.6.2. We assume that the length of each subinterval is given by Δx. First, recall that the area of a trapezoid with a height of h and bases of
length b and b is given by Area = h(b + b ) . We see that the first trapezoid has a height Δx and parallel bases of length f (x ) and f (x ). Thus, the area of the first trapezoid in
1 2
1
2
1 2 0 1
Figure 7.6.2 is
1
Δx(f (x0 ) + f (x1 )).
2
2
Δx and combining like terms, we have
b
Δx
∫ f (x) dx ≈ [f (x0 ) + 2 f (x1 ) + 2 f (x2 ) + 2 f (x3 ) + f (x4 )].
a 2
Set
Δx
Tn = [f (x0 ) + 2 f (x1 ) + 2 f (x2 ) + ⋯ + 2 f (xn−1 ) + f (xn )].
2
Before continuing, let’s make a few observations about the trapezoidal rule. First of all, it is useful to note that
n n
1
Tn = (Ln + Rn ) where L n = ∑ f (xi−1 )Δx and R n = ∑ f (xi )Δx.
2
i=1 i=1
That is, L and R approximate the integral using the left-hand and right-hand endpoints of each subinterval, respectively. In addition, a careful examination of Figure 7.6.3 leads us
n n
to make the following observations about using the trapezoidal rules and midpoint rules to estimate the definite integral of a nonnegative function. The trapezoidal rule tends to
overestimate the value of a definite integral systematically over intervals where the function is concave up and to underestimate the value of a definite integral systematically over
intervals where the function is concave down. On the other hand, the midpoint rule tends to average out these errors somewhat by partially overestimating and partially underestimating
the value of the definite integral over these same types of intervals. This leads us to hypothesize that, in general, the midpoint rule tends to be more accurate than the trapezoidal rule.
Figure 7.6.3 :The trapezoidal rule tends to be less accurate than the midpoint rule.
Solution
1−0
The endpoints of the subintervals consist of elements of the set P = {0,
1
4
,
1
2
,
3
4
, 1} and Δx = 4
=
1
4
. Thus,
1
2
1 1 1 1 3
∫ x dx ≈ ⋅ [f (0) + 2 f ( )+2 f ( )+2 f ( ) + f (1)]
4 2 4
0
2 4
1 1 1 9
= (0 + 2 ⋅ +2 ⋅ +2 ⋅ + 1)
8 16 4 16
11
= = 0.34375
32
Exercise 7.6.2
2
1
Use the trapezoidal rule with n = 2 to estimate ∫ dx.
1
x
Hint
1
Set Δx = . The endpoints of the subintervals are the elements of the set P = {1,
3
2
, 2} .
2
Answer
17
≈ 0.708333
24
If B is our estimate of some quantity having an actual value of A , then the absolute error is given by |A − B| .
The relative error is the error as a percentage of the actual value and is given by
∣ A−B ∣
∣ ∣ ⋅ 100%.
∣ A ∣
1
1
Solution: The calculated value is ∫ 2
x dx = and our estimate from the example is M 4 =
21
64
. Thus, the absolute error is given by ∣∣ 1
3
−
21
64
∣ =
∣ 192
1
≈ 0.0052.
0
3
1
1
Solution: The calculated value is ∫ 2
x dx = and our estimate from the example is T 4 =
11
32
. Thus, the absolute error is given by ∣∣ 1
3
−
11
32
∣ =
∣
1
96
≈ 0.0104.
0 3
Exercise 7.6.3
2
1
In an earlier checkpoint, we estimated ∫ dx to be 24
35
using M . The actual value of this integral is ln 2. Using
2
24
35
≈ 0.6857 and ln 2 ≈ 0.6931, calculate the absolute error
1
x
Hint
Use the previous examples as a guide.
Answer
absolute error ≈ 0.0074, and relative error ≈ 1.1%
Let f (x) be a continuous function over [a, b], having a second derivative f ′′
(x) over this interval. If M is the maximum value of |f ′′
(x)| over [a, b], then the upper bounds for the
b
3
M (b − a)
Error in Mn ≤ (7.6.1)
24n2
and
3
M (b − a)
Error in Tn ≤
2
12n
We can use these bounds to determine the value of n necessary to guarantee that the error in an estimate is less than a specified value.
Solution
We begin by determining the value of M , the maximum value of |f over [0, 1] for f (x) = e . Since f '(x) = 2x e we have
2 2
′′ x x
(x)| ,
2 2
′′ x 2 x
f (x) = 2 e + 4x e .
−
−−−
Thus, n ≥ √ 600e
24
≈ 8.24. Since n must be an integer satisfying this inequality, a choice of n = 9 would guarantee that
1
∣ 2
∣
x
∣∫ e dx − Mn ∣ < 0.01.
∣ 0 ∣
Analysis
We might have been tempted to round 8.24 down and choose n = 8 , but this would be incorrect because we must have an integer greater than or equal to 8.24. We need to keep in
mind that the error estimates provide an upper bound only for the error. The actual estimate may, in fact, be a much better approximation than is indicated by the error bound.
Exercise 7.6.4
1
Use Equation 7.6.1 to find an upper bound for the error in using M to estimate ∫ 4 x
2
dx.
0
Hint
f
′′
(x) = 2, so M = 2.
Answer
1
192
Simpson’s Rule
With the midpoint rule, we estimated areas of regions under curves by using rectangles. In a sense, we approximated the curve with piecewise constant functions. With the trapezoidal
rule, we approximated the curve by using piecewise linear functions. What if we were, instead, to approximate a curve using piecewise quadratic functions? With Simpson’s rule, we
x2 x2
do just this. We partition the interval into an even number of subintervals, each of equal width. Over the first pair of subintervals we approximate ∫ f (x) dx with ∫ ,
p(x) dx
x0 x0
where p(x) = Ax 2
+ Bx + C is the quadratic function passing through (x 0, f (x0 )), (x1 , f (x1 )), and (x 2, f (x2 )) (Figure 7.6.4). Over the next pair of subintervals we approximate
x4
∫ f (x) dx with the integral of another quadratic function passing through (x2 , f (x2 )), (x3 , f (x3 )), and (x4 , f (x4 )). This process is continued with each successive pair of
x2
subintervals.
Figure 7.6.4 : With Simpson’s rule, we approximate a definite integral by integrating a piecewise quadratic function.
To understand the formula that we obtain for Simpson’s rule, we begin by deriving a formula for this approximation over the first two subintervals. As we go through the derivation, we
need to keep in mind the following relationships:
2
f (x0 ) = p(x0 ) = Ax + Bx0 + C
0
2
f (x1 ) = p(x1 ) = Ax + Bx1 + C
1
2
f (x2 ) = p(x2 ) = Ax + Bx2 + C
2
Thus,
∫ f (x) dx ≈ ∫ p(x) dx
x0 x0
x2
2
=∫ (Ax + Bx + C ) dx
x0
x2
A 3
B 2 ∣
=( x + x + C x) ∣ Find the antiderivative.
3 2 ∣
x0
A B
3 3 2 2
= (x −x )+ (x − x ) + C (x2 − x0 ) Evaluate the antiderivative.
2 0 2 0
3 2
A B
2 2
= (x2 − x0 )(x + x2 x0 + x ) + (x2 − x0 )(x2 + x0 ) + C (x2 − x0 )
2 0
3 2
x2 − x0 x2 − x0
2 2
= (2A(x + x2 x0 + x ) + 3B(x2 + x0 ) + 6C ) Factor out .
2 0
6 6
Δx x2 − x0
2 2 2 2
= ((Ax + Bx2 + C ) + (Ax + Bx0 + C ) + A(x + 2 x2 x0 + x ) + 2B(x2 + x0 ) + 4C ) Rearrange the terms. Note: Δx =
2 0 2 0
3 2
Δx
2
= (f (x2 ) + f (x0 ) + A(x2 + x0 ) + 2B(x2 + x0 ) + 4C ) Factor and substitute:
3
2 2
f (x2 ) = Ax + Bx2 + C and f (x0 ) = Ax + Bx0 + C .
2 0
Δx
2
= (f (x2 ) + f (x0 ) + A(2 x1 ) + 2B(2 x1 ) + 4C ) Substitute x2 + x0 = 2 x1 .
3
x2 + x0
Note: x1 = is the midpoint.
2
Δx
2
= (f (x2 ) + 4f (x1 ) + f (x0 )). Expand and substitute f (x1 ) = Ax + Bx1 + C .
1
3
x4
x4
Δx
∫ f (x) dx ≈ (f (x4 ) + 4 f (x3 ) + f (x2 )).
x2
3
The pattern continues as we add pairs of subintervals to our approximation. The general rule may be stated as follows.
Simpson’s Rule
b −a
Assume that f (x) is continuous over [a, b] . Let n be a positive even integer and Δx = . Let [a, b] be divided into n subintervals, each of length Δx , with endpoints at
n
P = { x0 , x1 , x2 , … , xn }. Set
Δx
Sn = [f (x0 ) + 4 f (x1 ) + 2 f (x2 ) + 4 f (x3 ) + 2 f (x4 ) + ⋯ + 2 f (xn−2 ) + 4 f (xn−1 ) + f (xn )].
3
Then,
b
Just as the trapezoidal rule is the average of the left-hand and right-hand rules for estimating definite integrals, Simpson’s rule may be obtained from the midpoint and trapezoidal rules
by using a weighted average. It can be shown that S = ( ) M + ( ) T . 2n
2
3
n
1
3
n
It is also possible to put a bound on the error when using Simpson’s rule to approximate a definite integral. The bound in the error is given by the following rule:
Let f (x) be a continuous function over [a, b] having a fourth derivative, f (4)
, over this interval. If M is the maximum value of ∣∣f
(x)
(4)
(x)∣
∣ over [a, b], then the upper bound for
b
5
M (b − a)
Error in Sn ≤ .
4
180n
Use S to approximate ∫
2 x
3
dx . Estimate a bound for the error in S . 2
Solution
1−0
Since [0, 1] is divided into two intervals, each subinterval has length Δx = 2
=
1
2
. The endpoints of these subintervals are {0, 1
2
. If we set f (x) = x
, 1}
3
, then
1 1 1 1 1 1
S2 = ⋅ (f (0) + 4 f ( ) + f (1)) = (0 + 4 ⋅ + 1) = .
3 2 2 6 8 4
Since f (4)
(x) = 0 and consequently M = 0, we see that
1
1
This bound indicates that the value obtained through Simpson’s rule is exact. A quick check will verify that, in fact, ∫ 3
x dx = .
0
4
2
x
2
over [1, 4].
Solution
4
−−−− −
The length of y =
1
2
x
2
over [1, 4] is ∫
2
√1 + x dx . If we divide [1, 4] into six subintervals, then each subinterval has length Δx =
4−1
6
=
1
2
, and the endpoints of the
1
−−−− −
subintervals are {1, 3
2
, 2,
5
2
, 3,
7
2
, 4} . Setting f (x) = √1 + x
2
,
1 1 3 5 7
S6 = ⋅ (f (1) + 4f ( ) + 2f (2) + 4f ( ) + 2f (3) + 4f ( ) + f (4)).
3 2 2 2 2
Exercise 7.6.5
2
1
Use S to estimate ∫
2 dx.
1
x
Hint
1
S2 = Δx (f (x0 ) + 4f (x1 ) + f (x2 ))
3
Answer
25
≈ 0.694444
36
Key Concepts
We can use numerical integration to estimate the values of definite integrals when a closed form of the integral is difficult to find or when an approximate value only of the definite
integral is needed.
The most commonly used techniques for numerical integration are the midpoint rule, trapezoidal rule, and Simpson’s rule.
The midpoint rule approximates the definite integral using rectangular regions whereas the trapezoidal rule approximates the definite integral using trapezoidal approximations.
Simpson’s rule approximates the definite integral by first approximating the original function using piecewise quadratic functions.
Key Equations
Midpoint rule
n
Mn = ∑ f (mi )Δx
i=1
Trapezoidal rule
Δx
Tn = [f (x0 ) + 2 f (x1 ) + 2 f (x2 ) + ⋯ + 2 f (xn−1 ) + f (xn )]
2
Simpson’s rule
Δx
Sn = [f (x0 ) + 4 f (x1 ) + 2 f (x2 ) + 4 f (x3 ) + 2 f (x4 ) + 4 f (x5 ) + ⋯ + 2 f (xn−2 ) + 4 f (xn−1 ) + f (xn )]
3
Glossary
absolute error
if B is an estimate of some quantity having an actual value of A, then the absolute error is given by |A − B|
midpoint rule
n b
a rule that uses a Riemann sum of the form M n = ∑ f (mi )Δx , where m is the midpoint of the i
i
th
subinterval to approximate ∫ f (x) dx
a
i=1
numerical integration
relative error
error as a percentage of the actual value, given by
∣ A−B ∣
relative error = ∣ ∣ ⋅ 100%
∣ A ∣
Simpson’s rule
b
a rule that approximates ∫ f (x) dx using the area under a piecewise quadratic function.
a
b
The approximation S to ∫
n f (x) dx is given by
a
Δx
Sn = (f (x0 ) + 4 f (x1 ) + 2 f (x2 ) + 4 f (x3 ) + 2 f (x4 ) + ⋯ + 2 f (xn−2 ) + 4 f (xn−1 ) + f (xn )).
3
trapezoidal rule
b
The approximation T to ∫
n f (x) dx is given by
a
Δx
Tn = (f (x0 ) + 2 f (x1 ) + 2 f (x2 ) + ⋯ + 2 f (xn−1 ) + f (xn )).
2
This page titled 7.6: Numerical Integration is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by OpenStax.
7.6: Numerical Integration by Edwin “Jed” Herman, Gilbert Strang is licensed CC BY-NC-SA 4.0. Original source: https://openstax.org/details/books/calculus-volume-1.