Professional Documents
Culture Documents
Numerical Differentiation I
Numerical Analysis (9th Edition)
R L Burden & J D Faires
Beamer Presentation Slides
prepared by
John Carroll
Dublin City University
Introduction
General Formulas
3-pt Formulas
Outline
Numerical Differentiation I
2 / 33
Introduction
General Formulas
3-pt Formulas
Outline
Numerical Differentiation I
2 / 33
Introduction
General Formulas
3-pt Formulas
Outline
Numerical Differentiation I
2 / 33
Introduction
General Formulas
3-pt Formulas
Outline
Numerical Differentiation I
3 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
4 / 33
Introduction
General Formulas
3-pt Formulas
f (x0 ) = lim
Numerical Differentiation I
4 / 33
Introduction
General Formulas
3-pt Formulas
f (x0 ) = lim
Numerical Differentiation I
4 / 33
Introduction
General Formulas
3-pt Formulas
f (x0 ) = lim
Numerical Differentiation I
4 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
5 / 33
Introduction
General Formulas
3-pt Formulas
(x x0 )(x x1 )
f ((x ))
2!
Numerical Differentiation I
5 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x ) =
Differentiating gives
f (x) =
(x x0 )(x x0 h)
f (x0 + h) f (x0 )
+ Dx
f ((x))
h
2
Numerical Differentiation I
6 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x ) =
Differentiating gives
f (x) =
=
(x x0 )(x x0 h)
f (x0 + h) f (x0 )
+ Dx
f ((x))
h
2
f (x0 + h) f (x0 ) 2(x x0 ) h
+
f ((x))
h
2
(x x0 )(x x0 h)
+
Dx (f ((x)))
2
Numerical Differentiation I
6 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x ) =
Differentiating gives
f (x) =
=
(x x0 )(x x0 h)
f (x0 + h) f (x0 )
+ Dx
f ((x))
h
2
f (x0 + h) f (x0 ) 2(x x0 ) h
+
f ((x))
h
2
(x x0 )(x x0 h)
+
Dx (f ((x)))
2
f (x0 + h) f (x0 )
h
Numerical Differentiation I
6 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x)
f (x0 + h) f (x0 )
h
Numerical Differentiation I
7 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x)
f (x0 + h) f (x0 )
h
f (x0 + h) f (x0 ) h
f ()
h
2
Numerical Differentiation I
7 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x0 ) =
f (x0 + h) f (x0 ) h
f ()
h
2
Numerical Differentiation I
8 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
f (x0 ) =
f (x0 + h) f (x0 ) h
f ()
h
2
Numerical Differentiation I
8 / 33
Introduction
General Formulas
3-pt Formulas
Slope f 9(x 0)
Slope
x0
Numerical Analysis (Chapter 4)
f (x0 1 h) 2 f (x 0)
h
x0 1 h
Numerical Differentiation I
9 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
Example 1: f (x) = ln x
Use the forward-difference formula to approximate the derivative of
f (x) = ln x at x0 = 1.8 using h = 0.1, h = 0.05, and h = 0.01, and
determine bounds for the approximation errors.
Numerical Differentiation I
10 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
Example 1: f (x) = ln x
Use the forward-difference formula to approximate the derivative of
f (x) = ln x at x0 = 1.8 using h = 0.1, h = 0.05, and h = 0.01, and
determine bounds for the approximation errors.
Solution (1/3)
The forward-difference formula
f (1.8 + h) f (1.8)
h
with h = 0.1
Numerical Differentiation I
10 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation
Example 1: f (x) = ln x
Use the forward-difference formula to approximate the derivative of
f (x) = ln x at x0 = 1.8 using h = 0.1, h = 0.05, and h = 0.01, and
determine bounds for the approximation errors.
Solution (1/3)
The forward-difference formula
f (1.8 + h) f (1.8)
h
with h = 0.1 gives
ln 1.9 ln 1.8
0.64185389 0.58778667
=
= 0.5406722
0.1
0.1
Numerical Analysis (Chapter 4)
Numerical Differentiation I
10 / 33
Introduction
General Formulas
3-pt Formulas
Solution (2/3)
Because f (x) = 1/x 2 and 1.8 < < 1.9, a bound for this
approximation error is
|hf ()|
|h|
0.1
= 2 <
= 0.0154321
2
2
2(1.8)2
Numerical Differentiation I
11 / 33
Introduction
General Formulas
3-pt Formulas
Solution (2/3)
Because f (x) = 1/x 2 and 1.8 < < 1.9, a bound for this
approximation error is
|hf ()|
|h|
0.1
= 2 <
= 0.0154321
2
2
2(1.8)2
The approximation and error bounds when h = 0.05 and h = 0.01 are
found in a similar manner and the results are shown in the following
table.
Numerical Differentiation I
11 / 33
Introduction
General Formulas
3-pt Formulas
f (1.8 + h)
f (1.8 + h) f (1.8)
h
|h|
2(1.8)2
0.1
0.05
0.01
0.64185389
0.61518564
0.59332685
0.5406722
0.5479795
0.5540180
0.0154321
0.0077160
0.0015432
Since f (x) = 1/x The exact value of f (1.8) is 0.555, and in this case
the error bounds are quite close to the true approximation error.
Numerical Differentiation I
12 / 33
Introduction
General Formulas
3-pt Formulas
Outline
Numerical Differentiation I
13 / 33
Introduction
General Formulas
3-pt Formulas
Method of Construction
To obtain general derivative approximation formulas, suppose that
{x0 , x1 , . . . , xn } are (n + 1) distinct numbers in some interval I and
that f C n+1 (I).
From the interpolation error theorem
f (x) =
n
X
k =0
Theorem
we have
(x x0 ) (x xn ) (n+1)
f
((x))
(n + 1)!
Numerical Differentiation I
14 / 33
Introduction
General Formulas
3-pt Formulas
f (x) =
n
X
k =0
(x x0 ) (x xn ) (n+1)
f
((x))
(n + 1)!
f (x) =
n
X
k =0
+ Dx
(x x0 ) (x xn ) (n+1)
f
((x))
(n + 1!)
(x x0 ) (x xn )
Dx [f (n+1) ((x))]
(n + 1)!
Numerical Differentiation I
15 / 33
Introduction
General Formulas
3-pt Formulas
f (x) =
n
X
k =0
+ Dx
(x x0 ) (x xn ) (n+1)
f
((x))
(n + 1!)
(x x0 ) (x xn )
Dx [f (n+1) ((x))]
(n + 1)!
Numerical Differentiation I
16 / 33
Introduction
General Formulas
3-pt Formulas
f (x) =
n
X
k =0
+ Dx
(x x0 ) (x xn ) (n+1)
f
((x))
(n + 1!)
(x x0 ) (x xn )
Dx [f (n+1) ((x))]
(n + 1)!
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
Numerical Differentiation I
16 / 33
Introduction
General Formulas
3-pt Formulas
f (x) =
n
X
k =0
+ Dx
(x x0 ) (x xn ) (n+1)
f
((x))
(n + 1!)
(x x0 ) (x xn )
Dx [f (n+1) ((x))]
(n + 1)!
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
Numerical Differentiation I
16 / 33
Introduction
General Formulas
3-pt Formulas
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
Numerical Differentiation I
17 / 33
Introduction
General Formulas
3-pt Formulas
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
Numerical Differentiation I
17 / 33
Introduction
General Formulas
3-pt Formulas
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
Numerical Differentiation I
17 / 33
Introduction
General Formulas
3-pt Formulas
Outline
Numerical Differentiation I
18 / 33
Introduction
General Formulas
3-pt Formulas
(x x1 )(x x2 )
(x0 x1 )(x0 x2 )
Numerical Differentiation I
19 / 33
Introduction
General Formulas
3-pt Formulas
(x x1 )(x x2 )
(x0 x1 )(x0 x2 )
L0 (x) =
2x x1 x2
(x0 x1 )(x0 x2 )
we obtain
Numerical Differentiation I
19 / 33
Introduction
General Formulas
3-pt Formulas
(x x1 )(x x2 )
(x0 x1 )(x0 x2 )
L0 (x) =
2x x1 x2
(x0 x1 )(x0 x2 )
we obtain
2x x0 x2
(x1 x0 )(x1 x2 )
2x x0 x1
(x2 x0 )(x2 x1 )
Numerical Differentiation I
19 / 33
Introduction
General Formulas
3-pt Formulas
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
Numerical Differentiation I
20 / 33
Introduction
General Formulas
3-pt Formulas
n
X
k =0
n
f (n+1) ((xj )) Y
(xj xk )
(n + 1)!
k =0
k 6=j
becomes for n = 2:
f (xj ) = f (x0 )
2xj x1 x2
2xj x0 x2
+ f (x1 )
(x0 x1 )(x0 x2 )
(x1 x0 )(x1 x2 )
2
Y
2xj x0 x1
1
+ f (x2 )
+ f (3) (j )
(xj xk )
(x2 x0 )(x2 x1 )
6
k =0
k 6=j
Numerical Differentiation I
20 / 33
Introduction
General Formulas
3-pt Formulas
k =0
k 6=j
Assumption
Numerical Differentiation I
21 / 33
Introduction
General Formulas
3-pt Formulas
k =0
k 6=j
Assumption
The 3-point formulas become especially useful if the nodes are equally
spaced, that is, when
x1 = x0 + h
and x2 = x0 + 2h,
Numerical Differentiation I
for some h 6= 0
21 / 33
Introduction
General Formulas
3-pt Formulas
k =0
k 6=j
Assumption
The 3-point formulas become especially useful if the nodes are equally
spaced, that is, when
x1 = x0 + h
and x2 = x0 + 2h,
for some h 6= 0
Numerical Differentiation I
21 / 33
Introduction
General Formulas
3-pt Formulas
k =0
k 6=j
f (x0 ) =
f (x0 ) + 2f (x1 ) f (x2 ) + f (3) (0 )
h
2
2
3
Numerical Differentiation I
22 / 33
Introduction
General Formulas
3-pt Formulas
k =0
k 6=j
Numerical Differentiation I
23 / 33
Introduction
General Formulas
3-pt Formulas
k =0
k 6=j
Numerical Differentiation I
24 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
25 / 33
Introduction
General Formulas
3-pt Formulas
f (x0 ) =
f (x0 ) + 2f (x0 + h) f (x0 + 2h) + f (3) (0 )
h
2
2
3
2
1
1
1
h
f (x0 + h) =
f (x0 ) + f (x0 + 2h) f (3) (1 )
h
2
2
6
1 1
3
h2
f (x0 + 2h) =
f (x0 ) 2f (x0 + h) + f (x0 + 2h) + f (3) (2 )
h 2
2
3
Numerical Differentiation I
25 / 33
Introduction
General Formulas
3-pt Formulas
f (x0 ) =
f (x0 ) + 2f (x0 + h) f (x0 + 2h) + f (3) (0 )
h
2
2
3
2
1
1
1
h
f (x0 + h) =
f (x0 ) + f (x0 + 2h) f (3) (1 )
h
2
2
6
1 1
3
h2
f (x0 + 2h) =
f (x0 ) 2f (x0 + h) + f (x0 + 2h) + f (3) (2 )
h 2
2
3
As a matter of convenience, the variable substitution x0 for x0 + h is
used in the middle equation to change this formula to an approximation
for f (x0 ). A similar change, x0 for x0 + 2h, is used in the last equation.
Numerical Analysis (Chapter 4)
Numerical Differentiation I
25 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
26 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
26 / 33
Introduction
General Formulas
3-pt Formulas
Finally, note that the last of these equations can be obtained from the
first by simply replacing h with h, so there are actually only two
formulas.
Numerical Analysis (Chapter 4)
Numerical Differentiation I
26 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
27 / 33
Introduction
General Formulas
3-pt Formulas
Numerical Differentiation I
27 / 33
Introduction
General Formulas
3-pt Formulas
(1)
f (x0 ) =
(2)
f (x0 ) =
1
h2
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h
3
1
h2 (3)
[f (x0 + h) f (x0 h)] f (1 )
2h
6
Comments
Numerical Differentiation I
28 / 33
Introduction
General Formulas
3-pt Formulas
(1)
f (x0 ) =
(2)
f (x0 ) =
1
h2
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h
3
1
h2 (3)
[f (x0 + h) f (x0 h)] f (1 )
2h
6
Comments
Although the errors in both Eq. (1) and Eq. (2) are O(h2 ), the error
in Eq. (2) is approximately half the error in Eq. (1).
Numerical Differentiation I
28 / 33
Introduction
General Formulas
3-pt Formulas
(1)
f (x0 ) =
(2)
f (x0 ) =
1
h2
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h
3
1
h2 (3)
[f (x0 + h) f (x0 h)] f (1 )
2h
6
Comments
Although the errors in both Eq. (1) and Eq. (2) are O(h2 ), the error
in Eq. (2) is approximately half the error in Eq. (1).
This is because Eq. (2) uses data on both sides of x0 and Eq. (1)
uses data on only one side.
Numerical Differentiation I
28 / 33
Introduction
General Formulas
3-pt Formulas
(1)
f (x0 ) =
(2)
f (x0 ) =
1
h2
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) (0 )
2h
3
1
h2 (3)
[f (x0 + h) f (x0 h)] f (1 )
2h
6
Comments
Although the errors in both Eq. (1) and Eq. (2) are O(h2 ), the error
in Eq. (2) is approximately half the error in Eq. (1).
This is because Eq. (2) uses data on both sides of x0 and Eq. (1)
uses data on only one side.
Note also that f needs to be evaluated at only two points in
Eq. (2), whereas in Eq. (1) three evaluations are needed.
Numerical Analysis (Chapter 4)
Numerical Differentiation I
28 / 33
Introduction
General Formulas
3-pt Formulas
y
Slope f 9(x 0)
Slope
x0 2 h
Numerical Analysis (Chapter 4)
x0
1
[ f (x0 1 h) 2 f (x 0 2 h)]
2h
x0 1 h
Numerical Differentiation I
29 / 33
Introduction
General Formulas
3-pt Formulas
1
[f (x0 2h) 8f (x0 h) + 8f (x0 + h) f (x0 + 2h)]
12h
h4
+ f (5) ()
30
Numerical Differentiation I
30 / 33
Introduction
General Formulas
3-pt Formulas
1
[f (x0 2h) 8f (x0 h) + 8f (x0 + h) f (x0 + 2h)]
12h
h4
+ f (5) ()
30
1
[25f (x0 ) + 48f (x0 + h) 36f (x0 + 2h)
12h
h4
+ 16f (x0 + 3h) 3f (x0 + 4h)] + f (5) ()
5
Numerical Differentiation I
30 / 33
Questions?
Reference Material
f (n+1) ((x))
(x x0 )(x x1 ) (x xn )
(n + 1)!
n
X
k =0
Return to General Derivative Approximations1