Unit 12 Numerical Differentiation: Coefficients
Unit 12 Numerical Differentiation: Coefficients
Structure
12.1 Introduction
Objectives
12.2 Methods Based on Undetermined Coefficients
12.3 Methods Based on Finite Difference Operators
12.4 Methods Based on Interpolation
12.5 Richardson's Extrapolation
12.6 Optimum Choice of Step Length
12.7 Sulnma~y
12.8 Solutions/Answers
12.1 INTRODUCTION
Differentiation of a f u ~ ~ c t i of(x)
n is a fundamental and important concept in calculus.
W h e l ~the function is given explicitly its derivatives f'(x), fl'(x), ... etc. can be easily
found using the methods of calculus. For example, if f(x) = x2, we know that fl(x) =
2x, ftl(x) = 2 and all the higher order derivatives are zero. However, if the function is
not known explicitly but, we are given a table of values of f'(x) corresponding to a set
of values of x, then we cannot find the derivatives by using calculus methods. For
instance if f(x& represents distance travelled by a car in time xk, k = 0, 1, 2, ... seconds,
and we require the velocity and acceleration of the car at any time xk, then the
derivatives f '(x) and f "(x) representing velocity and acceleration respectively, cannot be
found analytically. Hence, the need arises to develop methods of differentiation to
obtain the derivative of a given function f(x), using the data given in the form of a
table which might have been formed as a result of scientific experiments.
Numerical inethods have the advantage that they are easily adaptable on calculators and
computers. These methods make use of the interpolating polynomials, which we
discussed in Block-3. We shall now discuss, in this unit, a few numerical differentiation
methods, namely, the method based on undetennined coefficients, methods based on
finite difference operators and methods based on interpolation.
\
Objectives
After studying this unit you should be able to
explain the iinportance of the numerical inethods over the calculus inethods;
use the method of undetennined coefficients and methods Lased on finit difference
operators to derive differentiation formulas and 'obtain the derivative of a function at
step points;
use the inethods derived from the interpolation formulas to obtain the derivative of a
function at off step points;
use Richandson's extrapolation method for obtaining higher order solutions;
obtain the optimal steplength for the given formula.
- (xm)- 0, for m
dP+ 1
1 0, 1, ...,p.
dxP+
Let us now illustrate this idea to find the numerical differentiation formula of 0 @4for f "(x&
Derivation of formula for fW(x)
Without loss of generality let us take xk = 0. We shall take the points symmetrically,
that is, x,= mb; m = 0, * 1, i2.
Let f-2, f-,, f, f,, f, denote the values of f(x) at x = -2h, - h, 0, h, 2h respectively.
In this case the formula given by Eqn. (1) can be written as
h2fl1(0) = Y-2f-2 + Y-lf-, + Y&+ ylfl + y2f2 (2)
Let us now make the formula exact for f(x) = 1, x, x2, x3, x4. Then, we have
f(x) = 1, ftl(0) = 0; f-2 = f-, = q, = f, = f , = 1
f(x) = x, fl'(0) = 0, f-2 = -2h; tl F 41; = 0; fl = b; f2 = 2b;
2 "
f(x) = x , f (0) f-2 = 4h2 = f2; ffl = b2 s f,; (,r 0; (3)
. .
f(x) = 2,f "(0) = 0. f, = - 8h3; f-, = -a3; 6 = 0; f, h3, 6 8h3
f(x) = x4 , f "(0) = 0; f-2 = 16h4 = f2; f-, = h4 = f,; 6 = 0
Numerical Differentiation
- ",
f l1((J) f r --f-,
12h2 [
+ 16fi-Mfo + 16f -f
21 (5)
Now, we know that the TE of the formula (5) is given by the f i t non-zero term in the
Taylor expression of
You must have observed that in the numerical differentiation formula discussed above, we
have to solve a linear system of equations. If the number of nodal points involved is large
or if we have to determine a method of hi@ order, then we have to solve a large system of
linear equations, which becomes tedious. To avoid this, we can use f i t e difference
operators to obtain the differentiation formulas, which we shall illustrate in the next section.
Numerical Differentiation Integration
and Solution of Differential Equations 12.3 METHODS BASED ON FINITE DIFFERENCE
OPERATORS
Thus, we have
hD = 2sinh-' (612)
Notice that this formula involves off-step points when operated on f(x). The formula
involving only the step points can be obtained by using the relation (13), i.e., '
hD = sinh-' (p6)
Thus, Eqns. (9), (lo), (15) and (16) give us the relations between hD and various
difference operators. Let us see bow we can use these relations to derive numerical
differentiation formulas for f; , f: etc. Numerical Differentiation
We first derive formulas for ftt. From Eqn. (9), we get
Thus forward difference formulas of qh), 0(h2), 0(h3 and 0(h4) can be obtained by '
retaining respectively 1, 2 3, and 4 terms of the relation (9) as follows :
Similarly the TE of formulas (20) and (21) can be calculated. Backward difference
formulas of qh), 0(h2), 6(h3) and 0(h3 for fkl can be obtained in the same way by .
using the equality (10) and retaining l,2,3 or 4 terms. We are leaving it as an exercise
for you to derive these formulas.
E2) Derive backward difference formulas for E,' of qb), 0(h2),0(h3) and 0(h4).
Central difference formulas for fl, can be obtained by using the relation (17), i.e.,
Note that relation (17) will give us methods of 0(h2) and 0@>,on retaining 1 and 2 tern,
b
S o l u t h : Were h = 0.1 and exact value of ex at x = 0.2 is 1.221402758.
it Using(l8), f '(0.2) =
-
f(0.3) f(0.2)
0.1
Numerical Differentiation Integration
Actual error 1.221402758 - 1.28456 = - 0.063157
- &-
r
-
and Solution of Differential Equations
1
Using (19), f '(0.2) f(0.4) + 4f(0.3) - 3f(0.2)] 1.21701
-
h2
TE -
3
f 111(0.2) -
-eo.2 O.,,,,'$ml;
= O.O1
3
Actual error = 0.004393
1
Using (24), f ' (0.2) = - (w.3) - f (0.1)) = 1.22344
0.2
I-E = - -
h2 f"'(0.2) = - -0.01
ea2= - 0.002035f;
6 6 ,
Actual m r = - 0.002037
1
f ' (0.2) = [-f (0.0) + Sf (0 I) - 8f (0.3) + f (0.4))
_
Ushg (U), = 1.221399167
We can write the forward difference methods of qh), 0(h2), m 3 ) and 0@> for f'; by
using Eqn. (26) and retaining 1, 2, 3 and 4 tenns as follows :
Backward difference formulas can be written in the same way by using Egn. (27).
Central differenceformulas of qh2) and 0@3 for f[ are obtained by using Eqa. (28)
and retaining 1 or 2 terms in the form :
E3) From the following table of values find f (6.0) using an O(h) formula and f I' (6.3)
usil~gan 0(h2) formula.
E4) Calculate the first and second derivatives of lnx at x = 500 from the following table.
Use q h 2 ) forward difference method. Compute TE and actual errors.
x : 500 510 520 530
f(x) : 6.2146 6.2344 6.2538 6.2729
In Secs. 12.2 and 12.3, we have derived numerical differentiation formulas to obtain the
derivative values at nodal points or step points, when the function values are given in
the form of a table. However, these methods cannot be used to find the derivative
values at off-step points. In the next section we shall derive methods which can be used
for finding the derivative values at the off-step points as well as at step-points.
In these methods, given the values of f(x) at a set of points x,,, xl,...%, the general
approach for deriving numerical differentiation formulas is to obtain the unique
interpolating polynomial P,(x) fitting the data. We then differentiate this polynomial q
times (q s n), to get (x). Tbe value 9Jq)(xk)then gives us the approximate value of
fi9)(x,J where X, may be a step point br an off-step point. We would like to point out
here that even when the original data are known to be accurate i.e. Pn(x,J = f ( G ,
k = 0, 1, 2, ..., n, yet the derivative values may differ considerably at these points. The
approximations may further deteriorate while finding the values at off-step points or as
the order of the derivative increases. However, these disadvantages are present in every
numerical differentiation formula, as in general, one does not know whether the function
representing a table of values has a derivative at every point or not.
We shall first derive differentiation formulas for the derivatives using non-uniform nodal
points. That is, when the diffetence between any two consecutive points is not uniform.
Nx) (36)
V X )= ix - xk) x1(xk)
-
and n: (x) = (X x0) (X xl) - (X- x,) (37)
Numerical Differeatiation Integration
and Solution o f Differential Equations xl(xk)= ( x ~ -x0)(xk- x ~ ) . . . ( x ~ Xk-l)(xk-
- X~+~)"-(X~- (38)
Since in Eqn. (40), the function 4 x ) is not known in the second term on the right
hand side, we cannot evaluate EL (x) directly. However, since at a nodal point xk,
n(x3 = 0, we obtain
If we want to obtain the differentiation formulas for any higher order, say qth
(1 s q r n) order derivative, then we differentiate Pn(x), q times and get
where,
(x- xl) (x- x2) 2x- xl- x,
Lo(x) = (xo- xl) (xo- x2) ; a x ) = (xo- xl) (xo- x,)
Hence, fl(x) = P; (x) = (x) fo + L; (x) fl + (x) f2 Numerical Differentiation
Exan r;e 5 : Given the following values of f(x) = In x, find the approximate value of
f 1 (2.C nd f"(2.0). Also find the errors of approximations.
.'. we get
Error is given by
Similarly,
Error ii given by
1 1
E; (xo) = 5 ~ - x2) f '"(2.0) + -(xo- x,) (x,-
( 2 ~ x1-
24
x2) [fN!?3) + fN(2.0)]
= -0.06917
You may now try the following exercise.
E5) Use Lagrange's interpolation to find f '(x) and f "(x) at x = 2.5'5.0 from the
following table
Let the data (xk, f3, k = 0, 1, ..., n be given at (n + 1) points where the step points xL;
k = 0, 1, ..., n are equispaced with step length h. That is, we have
with error
~x-xo)(x-xl)...(x-~n)An+l-
En (x) = f(a) xo<a<x,
(n+l)!hn+'
If we put
X
-
- Xo
s or x = xg + sh, then Eqns. (44) and (45) reduce respectively to
h
and
-
S(S 1). . . (s-n) h ( n + ~ ) f ( a + ~ )
n' (1' = (n + 1) ! (a)
which is same as formula (9) obtained in Sec. 123 by difference operator method. We can
obatin the derivative at any step or off-step point by finding the value of s and substituting
the same in Eqn. (48). The formula mrrespondug to Eqn. (47) in backward differences is,
Example 6 : Find the first and second derivatives of f(x) at x = 1.1 from the
following tabulated values.
Solution : Since we have to find the derivative at x = 1.1, we shall use the forward Numerical Differentiation
difference formula. The forward differences for the given data are given in Table 1.
Table 1
Substituting the values of Afo and A34, in Eqn. (50) from Table 1, we get
f '(1.1) = 0.63
To obtain the second derivative, we differentie formula (48) and obtain
- 1
f "(x) = ~ " ( x ) -
h
k2$+ (s- 1) A3fOI
Thus f"(l.1) = 6.6
Notp : . If you construct a folward difference interpolating polynomial P(x), fitting the
dataIgiven in Table 1, you will find that f(x) = P(x) = x3 - 3x + 2 Also, ff(l.l) = 6.3,
f"(l.1) = 6.6. The values obtained from this equation or directly as done above have to
be same as the interpolating polynomial is unique.
Solution : Since we are required to find the derivative at the end pint, we will use the
backward difference formula. The backward differencle table for the given data is given by
I Table 2
Numerical Differentiation Integration
and Solution of Differential Equations
Since x, = 0.4, h = 0.1, x = 0.4, we get s = 0
~hbstitutin~
the value of s in formula (49), we get
= 1.14913
How about trying a few exercises now ?
E6) The position qx) of a particle moving in a line at various times x, is given in the
following table. Estimate the velocity and acceleration of the particle at x = 1.5 and 35
Let fi9) (h) denote the approximate value of fiP)(x,J, obtained by using a formula of
order p, with steplength h and p9)(rh) denote the value of Pd(x,J obtained by using the
same method of order p, with steplength rh. Then,
f (40) = f (q)(~,J+ ChP + 0 (hp+') (5 1)
The expression on the right hand side of Eqn. (54) for finding the value of the qth
derivative by a certain method of order p has now become a method of order p + 1.
This technique of combining two computed values obtained by using the same method
with two different step sizes, to obtain higher order solutions is called Richardson's Numetkai Differentiation
extrapolation method.
terms, we have
TE= C ~ ~ ~ + C $ ~ + ' + C ~ ~ ~ + ~ + . . .
By repeated application of Rcihardson's extrapolation technique we can obtain solutions
of higher orders, i.e. O(hP+'), O(hP+a), 0(hP+3etc. by eliminating C1, Cz,C, respectively.
Let us see how this can be done.
Let g(xJ = fl(xJ be the exact value of the derivative, which is to be obtained and
be the value given by the O(hZ) method. The truncation error of this nlethod may be
written as
g(h) = g(xJ + clh2 + c414+ w6 ...
+ (55)
h
Let f; be evaluated with different step sizes - r = 0, 1, 2, . . .
2I'
Then, we have
Notke that the methods g(')(h) and g("(hL2) given by Eqns. (58) and (59) are 0(h>
approximations to g(xJ
I
Tbtse extrapolations can be stopped when
You may note that in Richardson's extrapolation, each improvement made for foxward
(or backward) difference formula increases the order of solutions by one, whereas for
central difference formula each improvement increases the order by two.
find f l(3).
Solutioa : Note that in this example xl = 3.0. The largest step h that can be taken
h
is h = 4. computations can also be done by using step lengths hl = - = 2 and
2
hp = hlR = 1.
we get
qh2) method.
qh2) method.
qh2) method.
g(l)(h) - )!(
48 - g@) m624*UW)1108
q h ? method.
3 3
0(h? method.
Numerical Differentiation
0(h6)method.
~ x a m p k9 : Let qx) = ex. Using a central difference formula of O(h3 find fl'(l)
Improve this value using Richardson's extrapolation by taking h = 0.1 and h = 0.05.
Solution : Witb h = 0.1 and
fk11 = e+~-~f,+fl-i 9
h2
we get
E8) Compute f "(0.6) from the following table using w 2 ) central difference formula.
Improve it by Richardson's extrapolation metbod using step lengths h = 0.4.0.2,O.l.
E9) Using central difference formula of 0@') find f "(0.3) Emuthe given table and improve
tbe adracy using Richardson's empolation method using step lengths h = 0.1'0.2
F
In the numerical differentiation methods, tbe trunation e m r is of tbe form ChP which
tends to zero as h-0. However, the metbod which approximates f (9)(x) contains hq in
Numerical Dimamtiation'ntevarionthe denominator. As h is successively reduced to smaller values, the truficatioil error
and Solution of Differential Equations
decreases but the round-off error in the method may inctease as we are dividing by a
small number. It may happen that after a certain critical value of h, the round-off enor
may become more dominant than the truncation error and the numerical results obtained
may start worsening as h is further reduced. The problem of finding a steplength h
small enough so that the truncation error is small, ye, large enough so that round-off
error does not dominate the actual error is referred to as themstep size dilemma. Such a
step length, if it can be determined is called the optimal steplength for that formula.
We shall now discuss in the next section how t9 determine the optimal steplength.
I 1
fk = (fk+ 1- fk)
2
Let f(x) = ex and we want to approximate fl(l) by taking h = - m = l , 2,..., 7.
lom'
We have from the differentiation formula (63),
The exact solution is f '(1) = 2.718282. The actual error is e - fl(l) and the truncation
-
error is ehn. With h = - 2
lorn'
m = 1, 2 ,..., 7, we have the results as given in Table 3.
Table 3
h f'(l) Actual error Approximate Tmllcation error
2 x lo-' 3.009175 - 0.290893 - 0.271828
If you look at Table 3, you will observe that the improved accuracy of the formula,
i.e. fl(l), with decreasing h does not continue indefinitely. Tbe truncation error agrees
with the a&ual error till h = 2 x = 0.002. As h is further reduced, the truncation
error ceases to approximate the actual error. This is because the actual error is
dominated by round-off error rather than the truncation error. This effect gets
worsened as h is reduced further. In such cases we determine the optimal steplength.
When f(x) is given ie tabular form, these values may not be exact These values ccntain
round-off errors. In other words, f(x3 = E, + E,, where f(x3 is the exact value, fk is the
tabulated value and E~ is the round-off error. For the numerical differentiation fnnnllla
(63), we have
If we take E = max (IE,~), (IE,+ ,I) and Mi = max Ifu(xjl, we Fmd that
We define the optimum value of h as the one which satisfies either of the following
col;ditions :
-
If we use the second condition (R( ITE 1 = min, we have
2E hMz
-+-
h 2
- min.
To find the mi~imumis Eqn. (65), we differentiate the left hand side of Eqn. (65) with
respect to
2E
--
hZ
Mz
I- -= 0 or, h2
2
- 4E
-or,
2
h 1 2qKT2..
Using this method and the first criterion, find the value of b and determine the value of
f1(2.0), from the following tabulated values of f(x) = In x. It is g i ~ e nthat the
maximum round-off error in the function evaluation is 5 x lo4
Solution : If E ~el, and E~ are the round-off errors in the given function evaluations of
fo, f,, f2 respectively, then we have
Hence h3 = -or
M,
12E
hTt =
R)"
-
-
fk+ I fk- 1 h2 rrr
2h -6 (a),
xk- 1< a < xk+1
determine hq, using the criteria. Numerical Diffir,.~tiation
(ii) 1 R ( + ( T E1 = minimum.
Using this method and the second criterion, fmd hqt for f(x) = I n x and determine
the value o f f '(2.03) from the following table of values of f(x), if it is given that the
maximum round-off error in the function evaluation is 5 x lod
-
W e now end this unit by giving a summary of what we have convered in it.
12.7 SUMMARY
In this unit w e have covered the following :
1) .If a function f(x) is not known explicitly but a table of values of €(x) corresponding to
a set of values of x is given then its derivatives can be obtained by numerical
differentiation methods.
2) Numerical differentiation formulas using
(i) the method of undetermined coefficients and
(ii) methods based on finite difference operators can be obtained for the derivatives
of a function at nodal or step points when the function is given in the form of s
table.
3) When it is required to find the derivative of a function at off-step points then the
methods mentioned in (2) above cannot be used. In such cases, the methods derived
from the interpolation formulas are useful.
4) Higher order solutions can be obtained by Richardson's extrapolation method which
uses the lower order solutions. These results are more accurate than the results
obtained directly from higher order differentiation formulas.
5) Round-off errors play a very important role in numerical differentiation. Sometimes,
if the step size is too small, the round-off errors gets magnified unmanageably. In
such cases the optimal step length for the given formula could be used, provided that
it can be detennined.
3 2 1
Solving we obtain a, = - a, = 2 s2= - -
2b
t
Exact value fl(x) = lh = 0.002; f "'(x) = - l/x2 = - 0.4 x lo-'
Actual error in f '(500) is 0, whereas in f "(500) it is 0.1 x lo-'. Truncation error in
f '(x) is
- ,Zf"' - -5.33
- -
x lo-' and in f "(x) it is "h2fn = 8.8 x 10-9
3 12
E5) fn tbe given problem xo = 1,xl = 2.. x2 s 3, x3 = 4 and f, = 1, fl = 16 f, = 81 and f:, = 256.
Constructing the Lagrange fundamental polynomials, we get
x3 - 7x2 + 14x - 8
) (x3 -6
3 )
-6x2+ l l x
6
1
P3(x) = G (x) f, + t;(4 f, + L;(x) f, L;( 4 f3 +
The exact values off '(x) and f "(x) are (from f(x) = x4)
E6) We are required to find fl(x) and fl'(x) at x = 1.5 and 3.5 which are off-step paihfi
Using the Newton's f(,.ward difference formula with xo = 0, x = 1.5, s = 1.5, w e p t
f'(1.5) = 8.7915 and f "(1.5) = -4.0834.
x f(x) Af A2 f A3 f A4 f
1.3 3.669
0.8i3
1.5 4.482 0.179
0.992 0.41
1.7 5.574 0.220 0.007
1.212 0.48
1.9 6.686 0.268 0.012
1.480 0.060
2.1 8.166 0.328 0.012
1.808 0.072
2.3 9.974 0.400
2.208
-2.5 12182
5:~ Taking xo = 1.5 we see tbat s = 0 and we obtain from tbe interpolation fonnula
6
E8) Use the q2) formula (33). With h = 0.1, f1'(0.6) = 1.25%, h = 0.2, f "(0.6) = 1.26545,
h = 0.4, f "(0.6) = 1.289394.
These two results are of q h 3 . To get qh6) result we repeat the extnpolation
technique and obtain
E10) If e-,, em 6, are the round-off errors in the given function evaluations f-,, 6,f,
respectively, and if E = mar ((E- ,1 , leal , 1el 1) and M3 = max ( f "'(x) 1 then
E h2
(R(a band (TEIr 7 M Y
Numerical Differeatiotion integration
and Solution of Differential Equations
-
Ifweuse IRJ JTEJ,weget
Ifweuse -
IRI lTEl =mi& then
-
For f(x) = In x and using the second aiterion, we get
b=Pt
-(30 x 1 0 ~ ~0.03.
) ~
f '(2.03) =
- -
0.72271 0.69315 o,492667.
0.06