Differentiation
Differentiation
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 129
Numerical differentiation
0 f (x0 + h) − f (x0 )
f (x0 ) = lim
h→0 h
We can approximate f 0 (x0 ) by
f (x0 + h) − f (x0 )
, for some small h
h
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 130
Numerical differentiation
Approximate f 0 (x0 ) by
x0 x0 " h x
1 00
0
f (x0 + h) = f (x0 ) + f (x0 )h + f (ξ)h2
2
0 f (x0 + h) − f (x0 ) 1 00
⇐⇒ f (x0 ) = − f (ξ)h
h 2
If ∃ M > 0 s.t. |f 00 (x)| ≤ M for all x near x0 , then
0 f (x0 + h) − f (x0 ) 1 00 Mh
Error = f (x0 ) − = f (ξ)h ≤
h 2 2
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 132
Example
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 133
Numerical differentiation
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 134
Three-point endpoint formula
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 135
Three-point endpoint formula
0 1 h2 (3)
f (x0 ) = −3f (x0 ) + 4f (x0 + h) − f (x0 + 2h) + f ξ(x0 )
2h 3
where ξ(x0 ) ∈ (x0 , x0 + 2h).
0 1 h2 (3)
f (x0 ) = f (x0 + h) − f (x0 − h) − f (ξ1 )
2h 6
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 137
Three-point midpoint formula
Numerical Differentiation and Integration
Slope f #(x 0)
1
Slope [ f (x0 ! h) " f (x 0 " h)]
2h
x0 " h x0 x0 ! h x
Five-Point Formulas
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 138
Five-point midpoint formula
0 1
f (x0 ) = f (x0 − 2h) − 8f (x0 − h) + 8f (x0 + h) − f (x0 + 2h)
12h
h4 (5)
+ f (ξ0 )
30
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 139
Five-point endpoint formula
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 140
Example
x f (x)
1.8 10.889365
1.9 12.703199
2.0 14.778112
2.1 17.148957
2.2 19.855030
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 141
Second derivative midpoint formula
00 1 h2 (4)
f (x0 ) = 2 f (x0 − h) − 2f (x0 ) + f (x0 + h) − f (ξ)
h 12
where x0 − h < ξ < x0 + h.
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 142
Roundoff error instability
1 h 2
f 0 (x0 ) = f (x0 + h) − f (x0 − h) − f (3) (ξ1 )
2h 6
for ξ1 ∈ (x0 − h, x0 + h).
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 143
Round-off error instability
˜ (x0 + h) − f˜ (x0 − h)
f ε h 2
f 0 (x0 ) − ≤ + M
2h h 6
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 144
Richardson’s extrapolation
M = N1 (h) + K1 h + K2 h2 + K3 h3 + · · ·
Therefore
" # ! !
h h h2 h3
M = N1 + N1 − N1 (h) +K2 − h2 +K3 − h3 +· · ·
2 2 2 4
Define " #
h h
N2 (h) = N1 + N1 − N1 (h)
2 2
K2 2 3K3 3
M = N2 (h) − h − h − ···
2 4
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 146
Example
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 147
Richardson’s extrapolation
6
Exercise: write a computer program for Richardson’s extrapolation.
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 148
Example
0 1 h2 000 h4 (5)
f (x0 ) = f (x0 + h) − f (x0 − h) − f (x0 ) − f (x0 ) − · · ·
2h 6 120
0 h2 000 h4 (5)
f (x0 ) = N1 (h) − f (x0 ) − f (x0 ) − · · ·
6 120
1
where N1 (h) = 2h f (x0 + h) − f (x0 − h) . Then compute
N1 (h), N1 ( h2 ), N2 (h), N1 ( h4 ), N2 ( h2 ), . . . in order.
Numerical Analysis I – Xiaojing Ye, Math & Stat, Georgia State University 149