Class
description
Transcript of Class
-
3.5 Numerical Differentiation (Finite Difference Formulas) Numerical differentiation is a process to find an estimate of a derivative of a given function at a given point. 3.5.1 Finite difference approximation of the derivative
The derivative of a function f(x) is defined by the limit
x
xfxxfxf
dx
xdfx
0lim' .
If x is sufficiently small, equation above can be rewritten as
x
xfxxfxf
'
with x represents a small change in x and it can be either positive or negative. To estimate the value of xf ' , we uses the forward, backward, and central finite difference formulas. Three such formulas are presented as follows with the derivative is calculated from the values of two points, as in Figure 3.7, by setting xxi , xxxi 1 , and xxxi 1 .
Figure 3.7. Finite Difference Approximation of First Derivative Forward difference is the slope of the line that connects points B and C:
x
xfxf
xx
xfxfxf ii
ii
iii
1
1
1'
Backward difference is the slope of the line that connects points A and B:
x
xfxf
xx
xfxfxf ii
ii
iii
1
1
1'
Central difference is the slope of the line that connects points A and C:
xxfxf
xx
xfxfxf ii
ii
iii
2' 11
11
11
xi xi-1 xi+1 x
f (x)
0
A B
C
-
3.5.2 Finite difference formulas using Taylor series expansion
The forward, backward, and central finite difference formulas are also can be derived by using Taylor series expansion as,
imimm
iiiiii xRxfm
hxf
hxf
hxf
hxhfxfxf !!4
'''!3
''!2
' )4(432
1 (1)
and
ininn
niiiiii xRxfn
hxf
hxf
hxf
hxhfxfxf !
1!4
'''!3
''!2
' 4432
1 (2)
where xh is the step size. mR and nR , called the remainders, are given by
1 !mj
ij
j
im xfj
hxR and
1 !
1nj
ij
jj
in xfj
hxR .
Subtracting Equation (2) from Equation (1) can produce the two-point central difference formula.
211
211
3
11
2
'''!32
'
'''!3
2'2
hOh
xfxf
xfh
h
xfxfxf
xfh
xhfxfxf
ii
iii
i
iiii
Hence it is showing that a more accurate formula as the error is of the order of 2hO has been obtained. 3.5.3 Summary of finite difference formulas
We can use the following difference formulas to compute the various derivatives.
First Derivative Differenc
e Type Formula
Truncation Error
Two-point forward
h
xfxfxf iii
1' hO
Two-point backward
h
xfxfxf iii
1'
hO
Two-point central
h
xfxfxf iii 2
' 11
2hO
Three-point forward
h
xfxfxfxf iiii 2
34' 12
2hO
Three-point backward
h
xfxfxfxf iiii 2
43' 21
2hO
Four-point central
h
xfxfxfxfxf iiiii 12
88' 2112
4hO
-
Second Derivative
Difference Type
Formula Truncatio
n Error Three-point forward
2
12 2''h
xfxfxfxf iiii
hO
Three-point backward
2
212''h
xfxfxfxf iiii
hO
Three-point central
2
11 2''h
xfxfxfxf iiii
2hO
Four-point forward
2
123 254''h
xfxfxfxfxf iiiii
2hO
Four-point backward
2
321 452''h
xfxfxfxfxf iiiii
2hO
Five-point central
2
2112
12
163016''
h
xfxfxfxfxfxf iiiiii
4hO
Third Derivative Differenc
e Type Formula
Truncation Error
Four-point forward
3
123 33'''h
xfxfxfxfxf iiiii
hO
Four-point backward
3
321 33'''h
xfxfxfxfxf iiiii
hO
Four-point central
3
2112
2
22'''
h
xfxfxfxfxf iiiii
2hO
Five-point forward
3
1234
2
51824143'''
h
xfxfxfxfxfxf iiiiii
2hO
Five-point backward
3
4321
2
31424185'''
h
xfxfxfxfxfxf iiiiii
2hO
Six-point central
3
321123
8
813138'''
h
xfxfxfxfxfxfxf iiiiiii
4hO
Fourth Derivative Differenc
e Type Formula
Truncation Error
Five-point forward
4
12344 464
h
xfxfxfxfxfxf iiiiii
hO
Five-point backward
4
43214 464
h
xfxfxfxfxfxf iiiiii
hO
-
Five-point central
4
21124 464
h
xfxfxfxfxfxf iiiiii
2hO
Six-point forward
4
123454 3142624112
h
xfxfxfxfxfxfxf iiiiiii
2hO
Six-point backward
4
543214 2112426143
h
xfxfxfxfxfxfxf iiiiiii
2hO
Seven-point central
4
3211234
6
1239563912
h
xfxfxfxfxfxfxfxf iiiiiiii
4hO
Example 3.19
Calculate the first derivative for the function 3 23 2f x x x x at point x = 5 numerically with the forward, backward and central finite difference formulas by using (i) points x = 4, x = 5, and x = 6. (ii) points x = 4.75, x = 5, and x = 5.25. Compare the results with the exact (analytical) derivative. Solution
Analytical differentiation:
2465' ,5when 149' 2
fx
xxxf
Numerical differentiation: (i)
x: 4 5 6 f(x): 228 430 726
Forward finite difference:
2961
430726
56
565'
ff
f %33.20100246
246296
error
Backward finite difference:
2021
228430
45
455'
ff
f %89.17100246
246202
error
Central finite difference:
2492
228726
46
465'
ff
f %22.1100246
246249
error
(ii)
x: 4.75 5 5.25 f(x): 371.390625 430 494.484375
Forward finite difference:
-
9375.25725.0
430484375.494
525.5
525.55'
ff
f %85.4100246
2469375.257
error
Backward finite difference:
4375.23425.0
390625.371430
75.45
75.455'
ff
f %70.4100246
2464375.234
error
Central finite difference:
1875.2465.0
390625.371484375.494
75.425.5
75.425.55'
ff
f
%08.0100246
2461875.246
error
The results show that the central finite difference formula gives a more accurate approximation. In addition, smaller step size h gives a significantly more accurate approximation. Example 3.20
The following table lists the population of Malaysia from 1980 2010.
Table 3.4. The Population of Malaysia in years 1980 2010
Year 1980 1985 1990 1995 2000 2005 2010 Population (millions) 13.9 15.9 18.1 20.7 23.5 26.5 28.3
Calculate the rate of growth of the population in millions per year for 2010. (i) Use two-point backward difference formula. (ii) Use three-point backward difference formula. (iii) Based on part (ii) above, apply the two-point central difference formula to predict the population in the year 2015. Solution
(i) yearper millions 36.05
5.263.28
20052010
200520102010'
ff
f
(ii)
10
5.235.2643.283
52
200020054201032010'
ffff
yearper millions 24.0
(iii) 5220052015
2010'ff
f
millions 9.28201510
5.26201524.0
f
f