MODULE V
INTRODUCTION
Lesson 1 Numerical
Differentiation
Lesson 2 Numerical Integration
EEPC102 Module V
MODULE V
NUMERICAL DIFFERENTIATION AND INTEGRATION
INTRODUCTION
Calculus is the mathematics of change. Because engineers must
continuously deal with systems and processes that change, calculus is an
essential tool of our profession. Standing at the heart of calculus are the related
mathematical concepts of differentiation and integration.
Mathematically, the derivative, which serves as the fundamental vehicle
for differentiation, represents the rate of change of a dependent variable with
respect to an independent variable. The mathematical definition of the
derivative begins with a difference approximation:
∆𝑦 𝑓(𝑥𝑖 + ∆𝑥 ) − 𝑓 (𝑥𝑖 )
=
∆𝑥 ∆𝑥
where y and f(x) are alternative representatives for the dependent variable and
x is the independent variable. If Δx is allowed to approach zero, the difference
becomes a derivative
𝑑𝑦 𝑓 (𝑥𝑖 + ∆𝑥 ) − 𝑓 (𝑥𝑖 )
= lim
𝑑𝑥 ∆𝑥→0 ∆𝑥
where dy/dx [which can also be designated as y’ or f’(xi)] is the first derivative
of y with respect to x evaluated at xi.
The second derivative represents the derivative of the first derivative,
𝑑2𝑦 𝑑 𝑑𝑦
2
= ( )
𝑑𝑥 𝑑𝑥 𝑑𝑥
Thus, the second derivative tells us how fast the slope is changing. It is commonly
referred to as the curvature, because a high value for the second derivative
means high curvature.
Partial derivatives can be thought of as taking the derivative of the function at
a point with all but one variable held constant. For example, given a function f
that depends on both x and y, the partial derivative of f with respect to x at an
arbitrary point (x, y) is defined as
EEPC102 Module V
𝜕𝑓 𝑓 (𝑥 + ∆𝑥, 𝑦) − 𝑓 (𝑥, 𝑦)
= 𝑙𝑖𝑚
𝜕𝑥 ∆𝑥→0 ∆𝑥
Similarly, the partial derivative of f with respect to y is defined as
𝜕𝑓 𝑓 (𝑥, 𝑦 + ∆𝑦) − 𝑓 (𝑥, 𝑦)
= 𝑙𝑖𝑚
𝜕𝑦 ∆𝑦→0 ∆𝑦
The inverse process to differentiation in calculus is integration. Mathematically,
integration is represented by
𝑏
𝐼 = ∫ 𝑓 (𝑥 )𝑑𝑥
𝑎
which stands for the integral of the function f(x) with respect to the independent
variable x, evaluated between the limits x = a to x = b. The function f(x) is
referred to as the integrand. The symbol ʃ is actually a stylized capital S that is
intended to signify the close connection between integration and summation.
OBJECTIVES
After studying the module, you should be able to:
1. To execute numerical differentiation and integration to a given set of
interpolation points without solving the polynomial.
2. To execute numerical integration to find an approximation for the value of the
definite integral where the function is not explicitly defined.
3. Implement numerical differentiation and integration with the use of Microsoft
Excel.
DIRECTIONS/ MODULE ORGANIZER
There are two lessons in the module. Read each lesson carefully then
answer the exercises/activities to find out how much you have benefited from
it. Work on these exercises carefully and submit your output to your instructor.
In case you encounter difficulty, discuss this with your instructor during
the face-to-face meeting.
EEPC102 Module V
Lesson 1
Numerical Differentiation
Numerical differentiation is a method of approximating the derivative of a
function f at particular value x. Often, particularly in physics and engineering, a
function may be too complicated to merit the work necessary to find the exact
derivative, or the function itself is unknown, and all that is available are some
points x and the function evaluated at those points. Numerical differentiation,
of which finite differences is just one approach, allows one to avoid these
complications by approximating the derivative.
High-accuracy divided-difference formulas can be generated by including
additional terms from the Taylor series expansion. For example, the forward
Taylor series expansion can be written
𝑓"(𝑥𝑖 ) 2
𝑓 (𝑥𝑖+1 ) = 𝑓(𝑥𝑖 ) + 𝑓 ′(𝑥𝑖 )ℎ + ℎ +⋯
2
Which can be solved for
𝑓(𝑥𝑖+1 ) − 𝑓 (𝑥𝑖 ) 𝑓"(𝑥𝑖 )
𝑓′(𝑥𝑖 ) = − ℎ + 𝑂(ℎ2 )
ℎ 2
truncating this result by excluding the second- and higher-derivative terms and
were thus left with a final result of
𝑓(𝑥𝑖+1 ) − 𝑓 (𝑥𝑖 )
𝑓′(𝑥𝑖 ) = + 𝑂(ℎ2 )
ℎ
In contrast to this approach, we now retain the second-derivative term by
substituting the following approximation of the second derivative
𝑓 (𝑥𝑖+2 ) − 2𝑓 (𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
𝑓"(𝑥𝑖 ) = + 𝑂(ℎ)
ℎ2
To yield
𝑓 (𝑥𝑖+1 ) − 𝑓 (𝑥𝑖 ) 𝑓 (𝑥𝑖+2 ) − 2𝑓 (𝑥𝑖+1 ) + 𝑓(𝑥𝑖 )
𝑓′(𝑥𝑖 ) = − ℎ + 𝑂(ℎ2 )
ℎ 2ℎ2
Or by collecting terms,
−𝑓(𝑥𝑖+2 ) + 4𝑓 (𝑥𝑖+1 ) − 3𝑓(𝑥𝑖 )
𝑓 ′(𝑥𝑖 ) = + 𝑂(ℎ2 )
2ℎ
EEPC102 Module V
Notice that inclusion of the second-derivative term has improved the accuracy
to 𝑂(ℎ2 ). Similar improved versions can be developed for the backward and
centered formulas as well as for the approximations of the higher derivatives.
Forward finite-divided-difference formula
First Derivative Error
𝑓 (𝑥𝑖+1 ) − 𝑓(𝑥𝑖 ) 𝑂(ℎ)
𝑓 ′ (𝑥𝑖 ) =
ℎ
−𝑓 𝑥𝑖+2 + 4 𝑓 (𝑥𝑖+1 ) − 3𝑓(𝑥𝑖 )
( ) 𝑂(ℎ2 )
𝑓 ′ (𝑥𝑖 ) =
2ℎ
Second Derivative
𝑓(𝑥𝑖+2 ) − 2𝑓(𝑥𝑖+1 ) + 𝑓(𝑥𝑖 ) 𝑂(ℎ)
𝑓"(𝑥𝑖 ) =
ℎ2
−𝑓 (𝑥𝑖+3 ) + 4𝑓 (𝑥𝑖+2 ) − 5𝑓 (𝑥𝑖+1 ) + 2𝑓(𝑥𝑖 ) 𝑂(ℎ2 )
𝑓"(𝑥𝑖 ) =
ℎ2
Backward finite-divided-difference formula
First Derivative Error
𝑓 (𝑥𝑖 ) − 𝑓(𝑥𝑖−1 ) 𝑂(ℎ)
𝑓 ′ (𝑥𝑖 ) =
ℎ
3𝑓 ( 𝑥𝑖 ) − 4 𝑓 ( 𝑥𝑖−1 ) + 𝑓(𝑥𝑖−2 ) 𝑂(ℎ2 )
𝑓 ′(𝑥𝑖 ) =
2ℎ
Second Derivative
𝑓(𝑥𝑖 ) − 2𝑓(𝑥𝑖−1 ) + 𝑓(𝑥𝑖−2 ) 𝑂(ℎ)
𝑓"(𝑥𝑖 ) =
ℎ2
2𝑓 (𝑥𝑖 ) + 5𝑓 (𝑥𝑖−1 ) + 4𝑓 (𝑥𝑖−2 ) − 𝑓(𝑥𝑖−3 ) 𝑂(ℎ2 )
𝑓"(𝑥𝑖 ) =
ℎ2
Centered finite-divided-difference formula
First Derivative Error
𝑓 (𝑥𝑖+1 ) − 𝑓(𝑥𝑖−1 ) 𝑂(ℎ2 )
𝑓 ′(𝑥𝑖 ) =
2ℎ
−𝑓 ( 𝑥𝑖+2 ) + 8 𝑓 ( 𝑥𝑖+1 ) − 8𝑓 (𝑥𝑖−1 ) + 𝑓(𝑥𝑖−2 ) 𝑂(ℎ4 )
𝑓 ′(𝑥𝑖 ) =
12ℎ
Second Derivative
𝑓(𝑥𝑖+1 ) − 2𝑓(𝑥𝑖 ) + 𝑓(𝑥𝑖−1 ) 𝑂(ℎ2 )
𝑓"(𝑥𝑖 ) =
ℎ2
𝑓"(𝑥𝑖 ) 𝑂(ℎ4 )
−𝑓(𝑥𝑖+2 ) + 16𝑓 (𝑥𝑖+1 ) − 30𝑓 (𝑥𝑖 ) + 16𝑓(𝑥𝑖−1 ) − 𝑓(𝑥𝑖−2 )
=
12ℎ2
Example:
EEPC102 Module V
Estimate the Derivative of
𝑓 (𝑥 ) = −0.1 𝑥 4 − 0.15 𝑥 3 − 0.5 𝑥 2 − 0.25 𝑥 + 1.2
At x= 0.5 using finite divided difference and a step size of h= 0.25. Also find
the ɛt
Solution: The data needed are
𝑥𝑖−2 = 0 𝑓(𝑥𝑖−2 ) = 1.2
𝑥𝑖−1 = 0.25 𝑓 (𝑥𝑖−2 ) = 1.1035156
𝑥𝑖 = 0.5 𝑓(𝑥𝑖 ) = 0.925
𝑥𝑖+1 = 0.75 𝑓 (𝑥𝑖+1 ) = 0.6363281
𝑥𝑖+2 = 1 𝑓 (𝑥𝑖+2 ) = 0.2
The forward difference of accuracy O(h2) is computed as
By calculus, the true value is -0.9125
−0.2 + 4(0.6363281) − 3(0.925)
𝑓 ′ (0.5) = = −0.859375 𝜀𝑡 = 5.82%
2(0.25)
The backward difference of accuracy O(h2) is computed as
3(0.925) − 4(1.1035156) + 1.2
𝑓 ′ (0.5) = = −0.878125 𝜀𝑡 = 3.77%
2(0.25)
The centered difference of accuracy O(h4) is computed as
−0.2 + 8(0.6363281) − 8(1.1035156) + 1.2
𝑓 ′ (0.5) = = −0.9125 𝜀𝑡 = 0%
12(0.25)
EEPC102 Module V