Chapter 19 Numerical Differentiation: Taylor Polynomials Lagrange Interpolation
Chapter 19 Numerical Differentiation: Taylor Polynomials Lagrange Interpolation
Chapter 19 Numerical Differentiation: Taylor Polynomials Lagrange Interpolation
x1 x2 x3
Numerical Differentiation
Forward difference
Backward difference
Centered difference
Forward difference
h
x
xi1 xi xi+1
Backward difference
h
x
xi1 xi xi+1
Centered difference
2h
x
xi1 xi xi+1
y
First Derivatives
f ( x )
x
i-2 i-1 i i+1 i+2
f ( x i 1 ) f ( x i ) y i 1 y i
Forward difference f ( x )
x i 1 x i x i 1 x i
Backward difference f ( x ) f ( x i ) f ( x i 1 ) y i y i 1
x i x i 1 x i x i 1
Central difference f ( x i 1 ) f ( x i 1 ) y i 1 y i 1
f ( x )
x i 1 x i 1 x i 1 x i 1
Truncation Errors
Uniform grid spacing
h2 h3
f ( x i 1 ) f ( x i h ) f ( x i ) hf ( x i ) f ( x i ) f ( x i )
2! 3!
2 3
f ( x ) f ( x h ) f ( x ) hf ( x ) h
f ( x i )
h
f ( x i )
i 1 i i i
2! 3!
f ( xi1 ) f ( xi ) h
forward : f ( x i ) f ( 1 ) O(h)
h 2
f ( xi ) f ( xi 1 ) h
backward : f ( x i ) f ( 2 ) O(h)
h 2
f ( xi 1 ) f ( xi 1 ) h2
central : f ( x i ) f ( 3 ) O(h 2 )
2h 6
Example: First Derivatives
Use forward and backward difference approximations
to estimate the first derivative of
f ( x ) 0.1 x 4 0.15 x 3 0.5 x 2 0.25 x 1.2
at x = 0.5 with h = 0.5 and 0.25 (exact sol. = -0.9125)
Forward Difference
f ( 1) f (0.5 ) 0.2 0.925
h 0.5 , f ( 0.5 ) 1.45 , t 58.9%
1 0.5 0.5
h 0.25 , f (0.5 ) f (0.75 ) f (0.5 ) 0.63632813 0.925 1.155 , 26.5%
0.75 0.5 0.25
t
Backward Difference
f (0.5 ) f (0 ) 0.925 1.2
h 0.5 , f ( 0.5 ) 0.55 , t 39.7%
0.5 0 0.5
h 0.25 , f (0.5 ) f (0.5 ) f (0.25 ) 0.925 1.10351563 0.714 , 21.7%
0.5 0.25 0.25
t
Example: First Derivative
Use central difference approximation to estimate the
first derivative of
f ( x ) 0.1 x 4 0.15 x 3 0.5 x 2 0.25 x 1.2
at x = 0.5 with h = 0.5 and 0.25 (exact sol. = -0.9125)
Central Difference
f ( 1 ) f ( 0 ) 0.2 1.2
h 0.5 , f ( 0.5 ) 1.0 , t 9.6%
10 1
f ( 0.75 ) f ( 0.25 )
h 0.25 , f ( 0.5 )
0.75 0.25
0.63632813 1.10351563
0.934 , t 2.4%
0.5
Second-Derivatives
Taylor-series expansion
Uniform grid spacing
h2 h3 h4
f ( x i 1 ) f ( x i ) hf ( x i ) f ( x i ) f ( x i ) f ( x i )
2! 3! 4!
2 3 4
f ( x ) f ( x ) hf ( x ) h f ( x ) h f ( x ) h f ( x )
i 1 i i
2!
i
3!
i
4!
i
h2 h4
f ( x i 1 ) f ( x i 1 ) 2 f ( x i ) f ( x i ) f ( x i )
2! 4!
f ( x i 1 ) 2 f ( xi ) f ( xi 1 ) h2
f ( xi ) 2
f ( )
h 4!
Centered Finite-Divided Differences
Forward Finite-divided differences
Backward finite-divided differences
First Derivatives
f ( x )
Parabolic curve
4D( h / 2) D( h)
4*(2) - (1), f ' O( h )
4
3
f (1) f (0)
D1 ( h 0.5) 1.0, t 9.6%
1 0
f (0.75) f (0.25)
D2 ( h 0.25) 0.934, t 2.4%
0.75 0.25
4 D2 D1
D 0.9125, t 0%
3
General Three-Point Formula
Lagrange interpolation polynomial for
unequally spaced data
f ( x ) Li 1 ( x ) f ( x i 1 ) Li ( x ) f ( x i ) Li 1 ( x ) f ( x i 1 )
( x x i )( x x i 1 )
f ( xi 1 )
( x i 1 x i )( x i 1 x i 1 )
( x x i 1 )( x x i 1 )
f ( xi )
( x i x i 1 )( x i x i 1 )
( x x i 1 )( x x i )
f ( xi1 )
( x i 1 x i 1 )( x i 1 x i )
Lagrange Interpolation
1st-order Lagrange polynomial
x x1 x x0
f1 ( x ) L0 f ( x0 ) L1 ( x ) f ( x1 ) f ( x0 ) f ( x1 )
x0 x1 x1 x0
x0 x1 x2
L1(x)f(x1)
General Three-Point Formula
Lagrange interpolation polynomial for
unequally spaced data
f ( x ) Li 1 ( x ) f ( x i 1 ) Li ( x ) f ( x i ) Li 1 ( x ) f ( x i 1 )
( x x i )( x x i 1 ) ( x x i 1 )( x x i 1 )
f ( xi 1 ) f ( xi )
( x i 1 x i )( x i 1 x i 1 ) ( x i x i 1 )( x i x i 1 )
( x x i 1 )( x x i )
f ( xi1 )
( x i 1 x i 1 )( x i 1 x i )
First derivative
2 x xi xi1 2 x xi 1 xi 1
f ( x ) f ( x i 1 ) f ( xi )
( x i 1 x i )( x i 1 x i 1 ) ( x i x i 1 )( x i x i 1 )
2 x x i 1 xi
f ( xi1 )
( x i 1 x i 1 )( x i 1 x i )
Second Derivative
First Derivative for unequally spaced data
2 x xi xi1 2 x xi 1 xi 1
f ( x ) f ( x i 1 ) f ( xi )
( x i 1 x i )( x i 1 x i 1 ) ( x i x i 1 )( x i x i 1 )
2 x x i 1 xi
f ( xi1 )
( x i 1 x i 1 )( x i 1 x i )