Академический Документы
Профессиональный Документы
Культура Документы
Numérica
15 40.2
Taylor’s Expansion
1
f ( x h) f ( x ) f ( x ) h f ( x ) h O ( h )
2 3
2
1
f ( x)h f ( x h) f ( x) f ( x)h 2 O(h 3 )
2
f ( x h) f ( x ) 1
f ( x) f ( x)h O(h 2 )
h 2
Forward Difference Formula for f (x)
f ( x h) f ( x )
f ( x) error O(h)
h
Geometrically
f (x)
f (x)
f ( x h) f ( x)
h
x xh
Backward Difference Formula for f (x)
Similarly
1
f ( x h) f ( x) f ( x)h f ( x)h 2 O(h3 )
2
Geometrically
f ( x ) f ( x h)
f ( x) f (x)
h
error O(h) f ( x) f ( x h)
h
xh x x
Central Difference Formula for f (x)
1 1 1
f ( x h) f ( x) f ( x)h f ( x)h 2 f ( x)h3 f ( 4) ( x)h 4 O(h5 )
2 6 4!
1 1 1
–) f ( x h) f ( x) f ( x)h f ( x)h 2 f ( x)h3 f ( 4) ( x)h 4 O(h5 )
2 6 4!
1
f ( x h) f ( x h) 2hf ( x) f ( x)h3 O( h 5 )
3
1
2hf ( x) f ( x h) f ( x h) f ( x)h3 O(h5 )
3
Central Difference Formula for f (x)
f ( x h) f ( x h )
f ( x)
2h
Geometrically
error O(h )2
f (x)
f (x)
f ( x h) f ( x h)
2h
xh x xh x
First Derivatives - Example:
Use forward ,backward and centered 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
First Derivatives - Example:
• Central Difference
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
Example
• Remarks:
2 6
1 4 1
f ( x 2h) 2 f ( x h) f ( x) f ( x)h 2 [2 2 ] f ( x)h3[ ] O(h 4 )
2 3 3
f ( x)h2 f ( x 2h) 2 f ( x h) f ( x) f ( x)h3 O(h4 )
f ( x 2 h ) 2 f ( x h) f ( x )
f ( x)
h2
error O(h)
Backward Difference Formula for f (x)
1 1
f ( x 2h) f ( x) f ( x)2h f ( x)(2h) f ( x)(2h)3 O(h 4 )
2
2 6
–2) f ( x h) f ( x) f ( x)h 1 f ( x)h 2 1 f ( x)h3 O(h 4 )
2 6
1 3 4 1
f ( x 2h) 2 f ( x h) f ( x) f ( x)h [2 2 ] f ( x)h [ ] O(h 4 )
2
2 3 3
f ( x)h2 f ( x 2h) 2 f ( x h) f ( x) f ( x)h3 O(h4 )
f ( x ) 2 f ( x h) f ( x 2h)
f ( x) 2
h
error O(h)
Central Difference Formula for f (x)
1 1 1
f ( x h) f ( x) f ( x)h f ( x)h 2 f ( x)h3 f ( 4) ( x)h 4 O(h5 )
2 6 4!
1 1 1
+) f ( x h) f ( x) f ( x)h f ( x)h 2 f ( x)h3 f ( 4) ( x)h 4 O(h5 )
2 6 4!
1 ( 4)
f ( x h) f ( x h) 2 f ( x) f ( x)h 2 f ( x ) h 4 O( h 6 )
12
f ( x h) f ( x h) 2 f ( x)
f ( x) 2
O ( h 2
)
h
f ( xi 1 ) f ( xi )
f ( xi )
/
h
f /
( x ) f /
( xi )
f ( xi )
// i 1
h
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
h2
f ( xi 3 ) 3 f ( xi 2 ) 3 f ( xi 1 ) f ( xi )
f ( xi )
///
h3
Numerical Differentiation
2. Backward difference
f ( xi ) f ( xi 1 )
f ( xi )
/
h
f /
( x ) f /
( xi 1 )
f ( xi )
// i
h
f ( xi ) 2 f ( xi 1 ) f ( xi 2 )
h2
f ( xi ) 3 f ( xi 1 ) 3 f ( xi 2 ) f ( xi 3 )
f ( xi )
///
h3
Numerical Differentiation
3. Centered difference
f ( xi 1 ) f ( xi 1 )
f ( xi )
/
2h
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
f ( xi )
//
h2
f ( xi 2 ) 2 f ( xi 1 ) 2 f ( xi 1 ) f ( xi 2 )
f ( xi )
///
2h 3
High Accuracy Differentiation
Formulas
• High-accuracy finite-difference formulas can be
generated by including additional terms from the Taylor
series expansion.
f ( x 2h) 4 f ( x h) 3 f ( x)
f ( x) O( h 2 )
2h
More Accurate FD Formula (cont)
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ( xi )
/
2h
f ( xi 3 ) 4 f ( xi 2 ) 5 f ( xi 1 ) 2 f ( xi )
f ( xi )
//
h2
f /// ( xi )
3 f ( xi 4 ) 14 f ( xi 3 ) 24 f ( xi 2 ) 18 f ( xi 1 ) 5 f ( xi )
2h 3
Higher Order Backward Divided Difference
3 f ( xi ) 4 f ( xi 1 ) f ( xi 2 )
f ( xi )
/
2h
2 f ( xi ) 5 f ( xi 1 ) 4 f ( xi 2 ) f ( xi 3 )
f ( xi )
//
h2
f /// ( xi )
5 f ( xi ) 18 f ( xi 1 ) 24 f ( xi 2 ) 14 f ( xi 3 ) 3 f ( xi 4 )
3
2h
Higher Order Central Divided Difference
f ( xi 2 ) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 )
f ( xi )
/
12h
f // ( xi )
f ( xi 2 ) 16 f ( xi 1 ) 30 f ( xi ) 16 f ( xi 1 ) f ( xi 2 )
2
12h
f /// ( xi )
f ( xi 3 ) 8 f ( xi 2 ) 13 f ( xi 1 ) 13 f ( xi 1 ) 8 f ( xi 2 ) f ( xi 3 )
8h3
Forward Finite-divided differences
Backward finite-divided differences
Centered Finite-Divided Differences
First Derivatives - Example:
Employing the high-accuracy formulas (h=0.25):
xi-2= 0.0 f(0.0) = 1.2
xi-1= 0.25 f(0.0) = 1.103516
xi = 0.5 f(0.5) = 0.925
xi+1 = 0.75 f(0.75) = 0.63633
xi+2 = 1.0 f(1.0) = 0.2
Forward Difference
f xi 2 4 f xi 1 3 f xi
f xi
2h
0.2 4(0.6363281) 3(0.925)
f 0.5 0.8594
2(0.25)
First Derivatives - Example:
Backward Difference
3(0.925) 4(1.035156) 1.2
f 0.5 0.8781
2(0.25)
Central Difference
0.2 8(0.636328) 8(1.035156)
f 0.5 0.9125
12(0.25)
Summary
True value: f`(0.5) = -0.9125
Basic h = 0.25 Forward Backward Centered
formulas O(h) O(h) O(h2)
Estimate -1.155 -0.714 -0.934
|t| 26.5% 21.7% 2.4%
f ( x h) f ( x h)
f ( x) O( h 2 )
2h
• Using Different h (h1, h2):
exact R1 c1h12
R2 c2 h22
• c1 and c2 could be different
Richardson Extrapolation (cont)
• If
c1 c2 c
R1 ch12 R2 ch22 exact
R2 R1
1
2 2
2
c h h R2 R1 c 2
h1 h22
R2 R1 2 R2 R1
exact R2 2 h R h 2
h1 h22
2 2 2 2
h
h22 12 1
h2
R2 R1
exact R2
1
h1 2
h2
Example
• f(x) = x3. Use CD with Richardson extrapolation to
compute f’(1)
3.0025 3.01
exact 3.0025 2
3.0000
0.1
1
0.05
Derivatives of unequally spaced data
One way to handle nonequispaced data is to fit a Lagrange interpolating polynomial to a
set of adjacent points that bracket the location value at which you want to evaluate the
derivative. Remember that this polynomial does not require that the points be equispaced.
The polynomial can then be differentiated analytically to yield a formula that can be used
to estimate the derivative.
Matlab Built-in functions for numerical
differentiation
MATLAB provides the diff function to use for computing
derivative estimates.