11.numerical Differentiation
11.numerical Differentiation
➢ Numerical Differentiation
a) Finite Difference Approximations
b) Richardson Extrapolation
NUMERICAL DIFFERENTIATION
Numerical differentiation deals with the following problem: We are given the
function y = f (x) and wish to obtain one of its derivatives at the point x = xk.
The term “given” means that we either have an algorithm for computing the
function, or we possess a set of discrete data points (xi , yi ), i = 0, 1, . . . , n.
In either case, we have access to a finite number of (x, y) data pairs from which
to compute the derivative.
(a)
(b)
• It is referred to as the «first forward difference» and h is called the step size, that is , the length of the interval over which the
approximation is made.
• It is termed a ‘’forward’’ difference because it utilizes data at i and i+1 to estimate the derivative.
• The Taylor series can be expanded backward to calculate previous values on the basis of a present value, as in
(c)
(d)
Finite divided difference can be represented generally as;
(e)
or
(f)
where Δfi is referred to as the first forward difference and h is called the step size, that is, the length of the interval over which the
approximation is made. It is termed a “forward” difference because it utilizes data at i and i + 1 to estimate the derivative (Fig. 2a).
The entire term Δf/h is referred to as a first finite divided difference.
This forward divided difference is but one of many that can be developed from the Taylor series to approximate derivatives
numerically. For example, backward and centered difference approximations of the first derivative can be developed in a fashion
similar to the derivation . The former utilizes values at xi−1 and xi (Fig. 2b), whereas the latter uses values that are equally spaced
around the point at which the derivative is estimated (Fig. 2c). More accurate approximations of the first derivative can be
developed by including higher-order terms of the Taylor series.
Backward Difference Approximation of the First Derivative: The Taylor series can be expanded backward to calculate a previous
value on the basis of a present value, as in
(1)
Truncating this equation after the first derivative and rearranging yields
(2)
∇ f1 is referred to as the first backward difference. See Fig. 2b for a graphical representation
Centered Difference Approximation of the First Derivative: A third way to approximate the first
derivative is to subtract Eq. (1) from the forward Taylor series expansion:
(3)
to yield
Or
(4)
Equation (4) is a centered difference representation of the first derivative. Notice that the truncation error is of the order of h2 in
contrast to the forward and backward approximations that were of the order of h. Consequently, the Taylor series analysis yields
the practical information that the centered difference is a more accurate representation of the derivative (Fig. 2.c). For example, if
we halve the step size using a forward or backward difference, we would approximately halve the truncation error, whereas for the
central difference, the error would be quartered.
Example 1: Use forward, backward and a centered difference approximation to estimate the first derivative of function:
at x = 0.5 using a step size h = 0.5. Also repeat the computation using h = 0.25 and compare the accuracy.
Solution:
Note that the derivative can be calculated directly as below and can be used to compute the true value as f’(0.5)=−0.9125
These values can be used to compute the forward divided difference [Eq. (e)],
For h = 0.25,
For both step sizes, the centered difference approximation is more accurate than forward or backward differences. Also, as predicted
by the Taylor series analysis, halving the step size approximately halves the error of the backward and forward differences and
quarters the error of the centered difference.
Finite Difference Approximations of Higher Derivatives: Besides first derivatives, the Taylor series expansion can be used to derive
numerical estimates of higher derivatives. To do this, we write a forward Taylor series expansion for f (xi+2) in terms of f (xi):
(5)
Equation (3) can be multiplied by 2 and subtracted from Eq. (5) to give
This relationship is called the second forward finite divided difference. Similar manipulations can be employed to derive a backward
version
(7)
As was the case with the first-derivative approximations, the centered case is more accurate. Notice also that the centered version can
be alternatively expressed as
Thus, just as the second derivative is a derivative of a derivative, the second divided difference approximation is a difference of two
first divided differences.
Example 2: Recall that in Example 1 we estimated the derivative of
where the errors were computed on the basis of the true value of −0.9125. Repeat this computation, but employ the high-accuracy
formulas from Figs.3 through 5.
Solution: The data needed for this example is
... x i-2 x i-1 xi x i+1 x i+2 ...
=0.098015
f xi+2 −f(xi−2 )
D(xi)=
(xi+2 )−(xi−2 )
And
f xi+1 −f(xi−1 )
D(xi-1)=
(xi+1 )−(xi−1 )
• Jaan Kiusalaas, “Numerical Methods in Engineering with Python 3”,3rd Edition, Cambridge, NY, 2013
• S.C. Chapra and R.P. Canale, “Numerical Methods for Engineers”, 6th ed., McGraw-Hill,, NY, 2010