Lesson 2
Numerical Integration
The Trapezoidal Rule is the most convenient method for Numerical Integration.
It approximates the area of the integral by approximating it as trapezoids by
dividing the area into parts. It corresponds to the case where the polynomial is
first order:
𝑏 𝑏
𝐼 = ∫ 𝑓 (𝑥 )𝑑𝑥 ≅ ∫ 𝑓1 (𝑥 )𝑑𝑥
𝑎 𝑎
Recall that a straight line can be represented as
𝑏
𝑓 (𝑏 ) − 𝑓 (𝑎 )
𝐼 = ∫ [𝑓 (𝑎) + (𝑥 − 𝑎)𝑑𝑥
𝑎 𝑏−𝑎
The result of the integration is
𝑓(𝑎) + 𝑓(𝑏)
𝐼 = (𝑏 − 𝑎 )
2
Which is called the trapezoidal rule.
Graphical Depiction of the Trapezoidal Rule
Single Application of Trapezoidal Rule
EEPC102 Module V
Integrate 𝑓(𝑥 ) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
From a=0 to b =0.8
Recall from calculus that the exact value of the integral can be
determined analytically to be 1.640533.
Solution.
𝑓 (0) = 0.2
𝑓 (0.8) = 0.232
Substituting to the trapezoidal rule formula:
0.2+0.232
𝐼 ≅ (0.8 − 0) = 0.1728
2
Which represents an error of
𝐸𝑡 = 1.640533 − 0.1728 = 1.467733
Multiple-Application Trapezoidal Rule
One way to improve the accuracy of the trapezoidal rule is to divide the
integration interval from a to b into a number of segments and apply the
method to each segment as shown in Figure 1. The areas of individual segments
can then be added to yield the integral for the entire interval. The resulting
equations are called multiple-application, or composite, integration formulas.
EEPC102 Module V
Figure 1: Illustration of the multiple-application
trapezoidal rule. (a) Two segments, (b) three
segments, (c) four segments, and (d) five segments.
The general format and nomenclature for multiple-
application integrals
Figure 2 shows the general format and nomenclature we will use to
characterize multiple-application integrals. There are 𝑛 + 1 equally spaced
base points (𝑥0 , 𝑥1 , 𝑥2 , . . . , 𝑥𝑛 ). Consequently, there are n segments of equal
width:
𝑏−𝑎
ℎ=
𝑛
EEPC102 Module V
If a and b are designated as x0 and xn, respectively, the total integral can be
represented as
𝑥1 𝑥2 𝑥𝑛
𝐼 = ∫ 𝑓 (𝑥 )𝑑𝑥 + ∫ 𝑓(𝑥 )𝑑𝑥 + ⋯ . + ∫ 𝑓(𝑥 )𝑑𝑥
𝑥0 𝑥1 𝑥𝑛−1
Substituting the trapezoidal rule for each integral yields
𝑓 (𝑥0 ) + 𝑓(𝑥1 ) 𝑓 (𝑥1 ) + 𝑓(𝑥2 ) 𝑓(𝑥𝑛−1 ) + 𝑓(𝑥𝑛 )
𝐼=ℎ + ℎ + ⋯ . +ℎ
2 2 2
or, grouping terms,
𝑛−1
ℎ
𝐼 = [𝑓(𝑥)0 + 2 ∑ 𝑓 (𝑥𝑖 ) + 𝑓(𝑥𝑛 )]
2
𝑖−1
Or
𝑓(𝑥0 ) + 2 ∑𝑛−1
𝑖−1 𝑓(𝑥𝑖 ) + 𝑓(𝑥𝑛 )
𝐼 = (𝑏 − 𝑎 )
2𝑛
Example:
1. Use the two-segment trapezoidal rule to estimate the integral of
𝑓(𝑥 ) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8
Solution.
n=2
0.8 − 0
ℎ=
2
𝑓 (0) = 0.2 𝑓(0.4) = 2.456 𝑓 (0.8) = 0.232
0.2 + 2(2.456) + 0.232
𝐼 = 0.8 ( ) = 1.0688
4
𝜀𝑡 = 1.640533 − 1.0688 = 0.57173 𝑡ℎ𝑢𝑠 𝜀𝑡 = 34.9%
2. Evaluate:
1
∫ 𝑥(𝑥 − 1)2 𝑑𝑥
0
EEPC102 Module V
Approximating the area as trapezoids. In this example, it will be divided into 5
parts.
Solving the 𝑓(𝑥) at each boundary
𝑓(𝑥) = 𝑥(𝑥 − 1)2
𝑓(0) = (0)(0 − 1) 2 = 0
𝑓(0.2) = (0.2)(0.2 − 1) 2 = 0.128
𝑓(0.4) = (0.4)(0.4 − 1) 2 = 0.144
𝑓(0.6) = (0.6)(0.6 − 1) 2 = 0.096
𝑓(0.8) = (0.8)(0.8 − 1) 2 = 0.032
𝑓(1) = (1)(1 − 1) 2 = 0
𝑓(𝑥0 ) + 2 ∑𝑛−1
𝑖−1 𝑓(𝑥𝑖 ) + 𝑓(𝑥𝑛 )
𝐼 = (𝑏 − 𝑎 )
2𝑛
0 + 2(0.128 + 0.144 + 0.096 + 0.032) + 0
𝐼 = (1 − 0)( = 0.08
2(5)
The actual integral is
EEPC102 Module V
Thus,
𝜀𝑡 = 0.0833333 − 0.08 = 0.0033333 𝑡ℎ𝑢𝑠 𝜀𝑡 = 0.04%
EEPC102 Module V