Math 23 Module 5
Math 23 Module 5
Module 5: Numerical
Differentiation and Integration
Prepared by:
Overview
In this module, we will discuss numerical differentiation and integration. Although differentiation is
taught before integration in calculus, we reverse their order in this module. We do this because
integration represents a more highly developed area of numerical methods. While numerical
differentiation is not as widely employed, it does have great significance for the solution of differential
equations. Hence, it makes sense to cover it as the last topic prior to describing differential equations
in Module 6.
The first part of the module is devoted to the most common approaches for numerical integration—
the Newton-Cotes formulas. These relationships are based on replacing a complicated function or
tabulated data with a simple polynomial that is easy to integrate. Three of the most widely used
Newton-Cotes formulas are discussed in detail: the trapezoidal rule, Simpson’s 1∕3 rule, and
Simpson’s 3∕8 rule. All these formulas are designed for cases where the data to be integrated are
evenly spaced.
In the last part of the module, we will discuss numerical differentiation. Topics include finite-
divided difference formulas, and Richardson’s extrapolation.
Learning Outcomes
At the end of this module, you should be able to:
1. Solve integration problems using Newton-Cotes formulas.
2. Use finite-difference formulas in solving derivatives.
5.1 INTRODUCTION
The function to be differentiated or integrated will typically be in one of the following three forms:
1. A simple continuous function such as a polynomial, an exponential, or a trigonometric function.
2. A complicated continuous function that is difficult or impossible to differentiate or integrate
directly.
3. A tabulated function, where values of 𝑥 and 𝑓(𝑥) are given at a number of discrete points, as
is often the case with experimental or field data.
In the first case, the derivative or integral of a simple function may be evaluated analytically using
calculus. For the second case, analytical solutions are often impractical, and sometimes impossible,
to obtain. In these instances, as well as in the third case of discrete data, approximate methods must
be employed.
In this module, we will cover the Newton-Cotes closed integration formulas such as trapezoidal
rule, Simpson’s 1/3 rule, and Simpson’s 3/8 rule. The closed forms are those where the data points
at the beginning and end of the limits of integration are known.
Example 5.1
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using trapezoidal rule.
Solution
The data needed for this example are
𝑥0 = 0, 𝑓(𝑥0 ) = 0.2
𝑥1 = 0.8, 𝑓(𝑥1 ) = 0.232
The integral estimate using Eq. (5.3) is
0.2 + 0.232
𝐼 = (0.8 − 0) [ ] = 0.1728
2
Note that the actual integral value is 1.6405.
Example 5.2
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using multiple-application trapezoidal rule for 𝑛 = 8 segments.
Solution
Using trapezoidal rule 𝑛 = 8, the step size is
𝑏 − 𝑎 0.8 − 0
ℎ= = = 0.1
𝑛 8
The calculations for the function values 𝑓(𝑥𝑖 ) and Σ𝑤𝑓(𝑥𝑖 ) is shown in Table 5.1.
Example 5.3
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using Simpson’s 1/3 rule.
Solution
For single application of Simpson’s 3/8 rule, 𝑛 = 3 (minimum) and ℎ = 0.4.
𝑥0 = 0, 𝑓(𝑥0 ) = 0.2
𝑥1 = 0.4, 𝑓(𝑥1 ) = 2.456
𝑥2 = 0.8, 𝑓(𝑥2 ) = 0.232
Example 5.4
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using multiple-application Simpson’s 1/3 rule for 𝑛 = 6 segments.
Solution
Using Simpson’s 1/3 rule 𝑛 = 6, the step size is
𝑏 − 𝑎 0.8 − 0
ℎ= = = 0.13333
𝑛 6
The calculations for the function values 𝑓(𝑥𝑖 ) and Σ𝑤𝑓(𝑥𝑖 ) is shown in Table 5.2.
Example 5.5
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using multiple-application Simpson’s 1/3 rule for 𝑛 = 8 segments.
Solution
Using Simpson’s 1/3 rule 𝑛 = 8, the step size is
𝑏 − 𝑎 0.8 − 0
ℎ= = = 0.1
𝑛 8
The calculations for the function values 𝑓(𝑥𝑖 ) and Σ𝑤𝑓(𝑥𝑖 ) is shown in Table 5.3.
Therefore, the integral estimate using Simpson’s 1/3 rule with 𝑛 = 8 segments is
𝑛−1 𝑛−2
ℎ 0.1
𝐼 = [𝑓(𝑥0 ) + 4 ∑ 𝑓(𝑥𝑖 ) + 2 ∑ 𝑓(𝑥𝑗 ) + 𝑓(𝑥𝑛 )] = [49.184] = 1.63947
3 3
𝑖=odd 𝑗=even
Example 5.6
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using Simpson’s 3/8 rule.
Solution
The single application of Simpson’s 3/8 rule requires four equally spaced points (𝑛 = 3, ℎ = 0.26667):
𝑥0 = 0, 𝑓(𝑥0 ) = 0.2
𝑥1 = 0.26667, 𝑓(𝑥1 ) = 1.43272
𝑥2 = 0.53333, 𝑓(𝑥2 ) = 3.48718
𝑥3 = 0.8, 𝑓(𝑥3 ) = 0.232
The integral estimate using Eq. (5.15) is
0.2 + 3(1.43272 + 3.48718) + 0.232
𝐼 = (0.8 − 0) [ ] = 1.51917
6
Note that the actual integral value is 1.6405.
Example 5.7
Estimate the integral of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
from 𝑎 = 0 to 𝑏 = 0.8 using multiple-application Simpson’s 3/8 rule for 𝑛 = 6 segments.
Therefore, the integral estimate using Simpson’s 3/8 rule with 𝑛 = 6 segments is
𝑛−1 𝑛−3
3ℎ 3(0.13333)
𝐼= [𝑓(𝑥0 ) + 3 ∑ 𝑓(𝑥𝑖 ) + 2 ∑ 𝑓(𝑥𝑗 ) + 𝑓(𝑥𝑛 )] = [32.65896] = 1.63295
8 8
𝑖=1,𝑖≠𝑗 𝑗=3𝑛
First Derivative
The slope is derived as
𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 )
𝑓 ′ (𝑥𝑖 ) = 𝑚(𝑠𝑙𝑜𝑝𝑒) =
𝑥𝑖+1 − 𝑥𝑖
Second Derivative
The truncated derivative version is
𝑓(𝑥𝑖+2 ) − 2𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
𝑓 ′′ (𝑥𝑖 ) = (5.19)
ℎ2
and the more accurate derivative version is
−𝑓(𝑥𝑖+3 ) + 4𝑓(𝑥𝑖+2 ) − 5𝑓(𝑥𝑖+1 ) + 2𝑓(𝑥𝑖 )
𝑓 ′′ (𝑥𝑖 ) = (5.20)
ℎ2
First Derivative
The slope is derived as
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑖−1 )
𝑓 ′ (𝑥𝑖 ) = 𝑚(𝑠𝑙𝑜𝑝𝑒) =
𝑥𝑖 − 𝑥𝑖−1
Thus, the truncated derivative version is
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑖−1 )
𝑓 ′ (𝑥𝑖 ) = (5.21)
ℎ
and the more accurate derivative version is
3𝑓(𝑥𝑖 ) − 4𝑓(𝑥𝑖−1 ) + 𝑓(𝑥𝑖−2 )
𝑓 ′ (𝑥𝑖 ) = (5.22)
2ℎ
Second Derivative
The truncated derivative version is
𝑓(𝑥𝑖 ) − 2𝑓(𝑥𝑖−1 ) + 𝑓(𝑥𝑖−2 )
𝑓 ′′ (𝑥𝑖 ) = (5.23)
ℎ2
and the more accurate derivative version is
2𝑓(𝑥𝑖 ) − 5𝑓(𝑥𝑖−1 ) + 4𝑓(𝑥𝑖−2 ) − 𝑓(𝑥𝑖−3 )
𝑓 ′′ (𝑥𝑖 ) = (5.24)
ℎ2
First Derivative
The slope is derived as
𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖−1 )
𝑓 ′ (𝑥𝑖 ) = 𝑚(𝑠𝑙𝑜𝑝𝑒) =
𝑥𝑖+1 − 𝑥𝑖−1
Thus, the truncated derivative version is
𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖−1 )
𝑓 ′ (𝑥𝑖 ) = (5.25)
2ℎ
and the more accurate derivative version is
−𝑓(𝑥𝑖+2 ) + 8𝑓(𝑥𝑖+1 ) − 8𝑓(𝑥𝑖−1 ) + 𝑓(𝑥𝑖−2 )
𝑓 ′ (𝑥𝑖 ) = (5.26)
12ℎ
Second Derivative
The truncated derivative version is
𝑓(𝑥𝑖+1 ) − 2𝑓(𝑥𝑖 ) + 𝑓(𝑥𝑖−1 )
𝑓 ′′ (𝑥𝑖 ) = (5.27)
ℎ2
and the more accurate derivative version is
−𝑓(𝑥𝑖+2 ) + 16𝑓(𝑥𝑖+1 ) − 30𝑓(𝑥𝑖 ) + 16𝑓(𝑥𝑖−1 ) − 𝑓(𝑥𝑖−2 )
𝑓 ′′ (𝑥𝑖 ) = (5.28)
12ℎ2
Example 5.8
Use forward, backward, and centered finite-divided difference truncated formula to estimate the first
derivative of
𝑓(𝑥) = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
at 𝑥 = 0.5 using a step size ℎ = 0.5. Repeat the computation using ℎ = 0.25. Note that the actual
derivative values can be calculated directly as
𝑓 ′ (𝑥) = −0.4𝑥 3 − 0.45𝑥 2 − 𝑥 − 0.25
and can be used to compute the actual derivative value of −0.9125.
Solution
For ℎ = 0.5, the function can be employed to determine
𝑥𝑖−1 = 0, 𝑓(𝑥𝑖−1 ) = 1.2
𝑥𝑖 = 0.5, 𝑓(𝑥𝑖 ) = 0.925
𝑥𝑖+1 = 1, 𝑓(𝑥𝑖+1 ) = 0.2
Example 5.9
Use forward, backward, and centered finite-divided difference more accurate formula to estimate the
first derivative of
𝑓(𝑥) = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
at 𝑥 = 0.5 using a step size ℎ = 0.25.
Solution
For ℎ = 0.25,
𝑥𝑖−2 = 0, 𝑓(𝑥𝑖−2 ) = 1.2
𝑥𝑖−1 = 0.25, 𝑓(𝑥𝑖−1 ) = 1.1035
𝑥𝑖 = 0.5, 𝑓(𝑥𝑖 ) = 0.925
𝑥𝑖+1 = 0.75, 𝑓(𝑥𝑖+1 ) = 0.6363
𝑥𝑖+2 = 1, 𝑓(𝑥𝑖+2 ) = 0.2
Using forward finite-divided difference more accurate formula [Eq. (5.18)],
−0.2 + 4(0.6363) − 3(0.925)
𝑓 ′ (𝑥𝑖 ) = = −0.8596
2(0.25)
Using backward finite-divided difference more accurate formula [Eq. (5.22)],
3(0.925) − 4(1.1035) + 1.2
𝑓 ′ (𝑥𝑖 ) = = −0.8780
2(0.25)
Using centered finite-divided difference more accurate formula [Eq. (5.26)],
−0.2 + 8(0.6363) − 8(1.1035) + 1.2
𝑓 ′ (𝑥𝑖 ) = = −0.9125
12(0.25)
Example 5.10
Estimate the first derivative of
𝑓(𝑥) = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
at 𝑥 = 0.5 employing step sizes of ℎ1 = 0.5 and ℎ2 = 0.25. Then use Eq. (5.31) to compute an
improved estimate for the centered finite-divided difference using Richardson extrapolation. Recall
that the true value is -0.9125.
Solution
The first-derivative estimates can be computed with centered differences as
0.2 − 1.2
𝐷(ℎ1 ) = = −1
2(0.5)
and
0.6363 − 1.1035
𝐷(ℎ2 ) = = −0.9344
2(0.25)
The improved estimate can be determined by applying Eq. (5.31) to give
4 1
𝐷 = (−0.9344) − (−1) = −0.9125
3 3
EXERCISE SET
𝑉, L 3 8 13 18 23
𝑃, atm 12.5 3.5 1.8 1.4 1.2
(a) Find the work performed on the gas numerically, using the 1-, 2-, and 4-segment trapezoidal
rule.
(b) Repeat (a) using the 1-, 2-, and 4-segment Simpson’s 1/3 rule.
6. Compute the first derivative of the following functions at the specified location and for the specified
step size using forward, backward, and centered finite-divided difference more accurate formula.
(a) 𝑦 = 𝑥 3 + 4𝑥 − 15 at 𝑥 = 0, ℎ = 0.25
(b) 𝑦 = 𝑥 2 cos 𝑥 at 𝑥 = 0.4, ℎ = 0.1
(c) 𝑦 = tan(𝑥/3) at 𝑥 = 3, ℎ = 0.5
(d) 𝑦 = sin(0.5√𝑥) /𝑥 at 𝑥 = 1, ℎ = 0.2
𝑥
(e) 𝑦 = 𝑒 + 𝑥 at 𝑥 = 2, ℎ = 0.2
7. Use Richardson extrapolation to estimate the first derivative of 𝑦 = cos 𝑥 at 𝑥 = 𝜋/4 using step
sizes of ℎ1 = 𝜋/3 and ℎ2 = 𝜋/6. Employ centered finite-divided difference truncated formula for
the initial estimates.
8. The following data were collected for the distance traveled versus time for a rocket:
𝑡, s 0 25 50 75 100 125
𝑦, km 0 32 58 78 92 100
SUPPLEMENTARY READING
Read Chapter 24: Case Studies for Numerical Integration and Differentiation on the book
Numerical Methods for Engineers (7th ed.) by Chapra and Canale. The purpose of this supplementary
reading is for you to apply the methods of numerical integration and differentiation discussed in this
module to practical engineering problems.
Two situations are most frequently encountered. In the first case, the function under study can
be expressed in analytic form but is too complicated to be readily evaluated using the methods of
calculus. Numerical methods are applied to situations of this type by using the analytic expression to
generate a table of arguments and function values. In the second case, the function to be evaluated
is inherently tabular in nature. This type of function usually represents a series of measurements,
observations, or some other empirical information.
REFERENCES
1. Chapra, S. C., Canale, R. P. (2015). Numerical Methods for Engineers (7th ed.). The McGraw-Hill
Companies, Inc.
2. Chapra, S. C. (2018). Applied Numerical Methods with MATLAB® for Engineers and Scientists
(4th ed.). The McGraw-Hill Companies, Inc.