Final
Final
′(
f ′′ (xi ) 2 f ′′′ (xi ) 3 f (4) (xi ) 4
f(xi+1 ) = f(xi ) + f xi )h + h + h + h +⋯
2! 3! 4!
where h = xi+1 − xi
Note: above is also Taylor series formula of f(xi+1 ).
Rewritten as:
′(
f ′′ (ξ) 2
f(xi+1 ) = f(xi ) + f xi )h + h
2!
where ξ is a value of x between xi and xi+1
′( )
f(xi+1 ) − f(xi ) f ′′ (ξ)
→ f xi = − h
h 2!
f ′′ (ξ)
truncation error = − h = O ( h)
2!
′( )
f(xi+1 ) − f(xi )
→ f xi = + O(h)
h
8.1.2 Two-point backward difference formula for first derivative
′′ ( ) ′′′ ( ) (4) ( )
f x i f x i f xi 4
f(xi−1 ) = f(xi ) − f ′ (xi )h + h2 − h3 + h +⋯
2! 3! 4!
′
f ′′ (ξ) 2
f(xi−1 ) = f(xi ) − f (xi )h + h
2!
′( )
f(xi ) − f(xi−1 ) f ′′ (ξ)
→ f xi = + h
h 2!
f ′′ (ξ)
truncation error = h = O ( h)
2!
f(xi ) − f(xi−1 )
→ f ′ (x i ) = + O(h)
h
8.1.3 Two-point central difference formula for first derivative
′(
f ′′ (xi ) 2 f ′′′ (ξ1 ) 3
f(xi+1 ) = f(xi ) + f xi )h + h + h
2! 3!
′
f ′′ (xi ) 2 f ′′′ (ξ2 ) 3
f(xi−1 ) = f(xi ) − f (xi )h + h − h
2! 3!
′′′ ( ) ′′′ ( )
f ξ 1 f ξ2 3
f(xi+1 ) − f(xi−1 ) = 2f ′ (xi )h + h3 + h
3! 3!
′( )
f(xi+1 ) − f(xi−1 ) f ′′′ (ξ1 ) f ′′′ (ξ2 ) 2
→ f xi = −( + )h
2h 2.3! 2.3!
f(xi+1 ) − f(xi−1 )
→ f ′ (x i ) = + O ( h2 )
2h
f ′′′ (ξ1 ) f ′′′ (ξ2 ) 2
truncation error = − ( + ) h = O(h2 )
2.3! 2.3!
8.1.4 Three-point forward and backward difference formulas for first derivative
Forward:
′(
f ′′ (xi ) 2 f ′′′ (ξ1 ) 3
f(xi+1 ) = f(xi ) + f xi )h + h + h
2! 3!
′
f ′′ (xi ) 2
f ′′′ (ξ2 )
f(xi+2 ) = f(xi ) + f (xi )2h + (2h) + (2h)3
2! 3!
′
f ξ1 3 f ′′′ (ξ2 )
′′′ ( )
4f(xi+1 ) − f(xi+2 ) = 3f(xi ) + 2f (xi )h + 4 h − (2h)3
3! 3!
′ 2
4f(xi+1 ) − f(xi+2 ) = 3f(xi ) + 2f (xi )h − 2hO(h )
−3f(xi ) + 4f(xi+1 ) − f(xi+2 )
f ′ (x i ) = + O(h2 )
2h
Similar, three point backward
3f(xi ) − 4f(xi−1 ) + f(xi−2 )
f ′ (x i ) = + O(h2 )
2h
Example 8-3: f(x) = x 3 . Calculate the first derivative at point x = 3 numerically
with the 3-point forward difference formula, using:
a. points x = 3, x = 4, x = 5
x 3 4 5
f′(x) 27 64 125
−3f(3) + 4f(4) − f(5) −3.27 + 4.64 − 125
f ′ (3) = = = 25
2.1 2
25 − 27
error = | | . 100% = 7.41%
27
8.2 Finite Difference Formulas of Second Derivative
8.2.1 Three-point central difference formula for the second derivative
f ′′ (xi ) 2 f ′′′ (xi ) 3 f (4) (xi ) 4
′(
f(xi+1 ) = f(xi ) + f xi )h + h + h + h +⋯
2! 3! 4!
′
f ′′ (xi ) 2 f ′′′ (xi ) 3 f (4) (xi ) 4
f(xi−1 ) = f(xi ) − f (xi )h + h − h + h +⋯
2! 3! 4!
f ′′ (xi ) 2 f (4) (xi ) 4
f(xi+1 ) + f(xi−1 ) = 2f(xi ) + 2 h +2 h +⋯
2! 4!
′′ ( )
f(xi−1 ) − 2f(xi ) + f(xi+1 )
f xi = 2
+ O(h2 )
h
8.2.2 Three-point forward and backward difference formula for the second
derivative
Forward:
′′ (
f(xi ) − 2f(xi+1 ) + f(xi+2 )
f xi ) = 2
+ O(h2 )
h
Backward:
f(xi−2 ) − 2f(xi−1 ) + f(xi )
f ′′ (xi ) = 2
+ O(h2 )
h
First derivative
Method Formula Truncatio
n Error
2-point f(xi+1 ) − f(xi ) O(h)
f ′ (x i ) =
forward h
3-point ′(
−3f(xi ) + 4f(xi+1 ) − f(xi+2 ) O ( h2 )
)
f xi =
forward 2h
2-point f(xi ) − f(xi−1 ) O(h)
f ′ (x i ) =
backwar h
d
3-point ′(
3f(xi ) − 4f(xi−1 ) + f(xi−2 ) O ( h2 )
f xi ) =
backwar 2h
d
2-point ′(
f(xi+1 ) − f(xi−1 ) O ( h2 )
)
f xi =
central 2h
4-point ′(
f(xi−2 ) − 8f(xi−1 ) + 8f(xi+1 ) − f(xi+2 ) O(h4 )
f xi ) =
central 12h
Second derivative
Method Formula Truncatio
n Error
3-point f(xi ) − 2f(xi+1 ) + f(xi+2 ) O(h)
f ′′ (xi ) =
forward h2
4-point ′′ (
2f(xi ) − 5f(xi+1 ) + 4f(xi+2 ) − f(xi+3 ) O ( h2 )
f )
xi =
forward h2
3-point f(xi−2 ) − 2f(xi−1 ) + f(xi ) O(h)
f ′′ (xi ) =
backwar h2
d
4-point ′′ (
2f(xi ) − 5f(xi−1 ) + 4f(xi−2 ) − f(xi−3 ) O ( h2 )
f xi ) =
backwar h2
d
3-point ′′ (
f(xi−1 ) − 2f(xi ) + f(xi+1 ) O ( h2 )
f )
xi =
central h2
5-point f ′′ (xi ) O(h4 )
central −f(xi−2 ) + 16f(xi−1 ) − 30f(xi ) + 16f(xi+1 ) − f(xi+2 )
=
12h2
Third derivative
Method Formula Truncatio
n Error
4-point −f(xi ) + 3f(xi+1 ) − 3f(xi+2 ) + f(xi+3 ) O(h)
f ′′′ (xi ) =
forward h3
5-point f ′′′ (xi ) O ( h2 )
forward −5f(xi ) + 18f(xi+1 ) − 24f(xi+2 ) + 14f(xi+3 )
−3f(xi+4 )
=
2h3
4-point −f(xi−3 ) + 3f(xi−2 ) − 3f(xi−1 ) + f(xi ) O(h)
f ′′′ (xi ) =
backwar h3
d
5-point f ′′′ (xi ) O ( h2 )
backwar 3f(xi−4 ) − 14f(xi−3 ) + 24f(xi−2 ) − 18f(xi−1 )
d +5f(xi )
=
2h3
4-point −f(xi−2 ) + 2f(xi−1 ) − 2f(xi+1 ) + f(xi+2 ) O ( h2 )
f ′′′ (xi ) =
central 2h3
6-point f(xi−3 ) − 8f(xi−2 ) + 13f(xi−1 ) − 13f(xi+1 ) O(h4 )
central +8f(xi+2 ) − f(xi+3 )
f ′′′ (xi ) =
8h3
Chapter 9: Integration
9.1.1 Rectangle method
𝑏 𝑏
𝐼(𝑓 ) = ∫ 𝑓(𝑥 )𝑑𝑥 = ∫ 𝑓(𝑎)𝑑𝑥 = 𝑓(𝑎)(𝑏 − 𝑎)
𝑎 𝑎
𝑏
𝑜𝑟 𝐼(𝑓 ) = ∫ 𝑓(𝑏)𝑑𝑥 = 𝑓(𝑏)(𝑏 − 𝑎)
𝑎
= ∑[𝑓(𝑥𝑖 )(𝑥𝑖+1 − 𝑥𝑖 )]
𝑖=1
9.2.1 Midpoint
𝑏 𝑏
𝑎+𝑏 𝑎+𝑏
𝐼 (𝑓 ) = ∫ 𝑓 (𝑥 )𝑑𝑥 = ∫ 𝑓 ( ) 𝑑𝑥 = 𝑓 ( ) (𝑏 − 𝑎)
𝑎 𝑎 2 2
9.2.2 Composite Midpoint
Domain [𝑎, 𝑏] is divided into N subintervals by 𝑁 + 1 points 𝑥1 , 𝑥2 , … , 𝑥𝑁+1
where 𝑥1 = 𝑎, 𝑥𝑁+1 = 𝑏
𝑏
𝐼 (𝑓 ) = ∫ 𝑓 (𝑥 )𝑑𝑥
𝑎
𝑥1 + 𝑥2 𝑥2 + 𝑥3
= 𝑓( ) (𝑥2 − 𝑥1 ) + 𝑓 ( ) (𝑥3 − 𝑥2 ) + ⋯
2 2
𝑥𝑁 + 𝑥𝑁+1
+𝑓( ) (𝑥𝑁+1 − 𝑥𝑁 )
2
𝑁
𝑥𝑖 + 𝑥𝑖+1
= ∑[𝑓( )(𝑥𝑖+1 − 𝑥𝑖 )]
2
𝑖=1
9.3.1 Trapezoidal
𝑏 𝑏
𝑓(𝑏) − 𝑓(𝑎)
𝐼(𝑓 ) = ∫ 𝑓(𝑥 )𝑑𝑥 = ∫ (𝑓(𝑎) + (𝑥 − 𝑎) )𝑑𝑥
𝑎 𝑎 𝑏 − 𝑎
1 𝑓 (𝑎 ) + 𝑓 (𝑏 )
= 𝑓 (𝑎)(𝑏 − 𝑎) + [𝑓 (𝑏) − 𝑓 (𝑎)](𝑏 − 𝑎) = (𝑏 − 𝑎)
2 2
9.3.2 Composite Trapezoidal
Domain [𝑎, 𝑏] is divided into N subintervals by 𝑁 + 1 points 𝑥1 , 𝑥2 , … , 𝑥𝑁+1
where 𝑥1 = 𝑎, 𝑥𝑁+1 = 𝑏
𝑏
𝐼 (𝑓 ) = ∫ 𝑓 (𝑥 )𝑑𝑥
𝑎
𝑓(𝑥1 ) + 𝑓(𝑥2 ) 𝑓 (𝑥2 ) + 𝑓 (𝑥3 )
= ( )
𝑥2 − 𝑥1 + (𝑥3 − 𝑥2 ) + ⋯
2 2
𝑓(𝑥𝑁 ) + 𝑓 (𝑥𝑁+1 )
+ (𝑥𝑁+1 − 𝑥𝑁 )
2
𝑁
1
= ∑[𝑓 (𝑥𝑖 ) + 𝑓(𝑥𝑖+1 )](𝑥𝑖+1 − 𝑥𝑖 )]
2
𝑖=1
ℎ
𝐼 (𝑓 ) = [𝑓 (𝑥1 ) + 4𝑓 (𝑥2 ) + 𝑓 (𝑥3 ) + 𝑓(𝑥3 ) + 4𝑓 (𝑥4 ) + 𝑓 (𝑥5 ) + ⋯ + 𝑓(𝑥𝑁−1 )
3
+ 4𝑓 (𝑥𝑁 ) + 𝑓 (𝑥3 )]
𝑁 𝑁−1
ℎ
= [𝑓(𝑎) + 4 ∑ 𝑓 (𝑥𝑖 ) + 2 ∑ 𝑓 (𝑥𝑖 ) + 𝑓 (𝑏)]
3
𝑖=2,4,6,… 𝑖=3,5,7,…
a. rectangle
𝑏 𝑁
b. trapezoidal
𝑁−1
ℎ
𝐼(𝑓 ) = [𝑓 (𝑎) + 𝑓 (𝑏)] + ℎ ∑ 𝑓(𝑥𝑖 )
2
𝑖=2
0.3
ℎ = 0.3, 𝐼(𝑓 ) = (0.5 + 4.8) + 0.3(0.6 + ⋯ + 3.2) = 3.165
2
0.6
ℎ = 0.6, 𝐼(𝑓 ) = (0.5 + 4.8) + 0.6(0.8 + 2) = 3.27
2
c. Simpson’s 3/8
𝑁−1 𝑁−2
3ℎ
𝐼 (𝑓 ) = [𝑓(𝑎) + 3 ∑ [𝑓(𝑥𝑖 ) + 𝑓 (𝑥𝑖+1 )] + 2 ∑ 𝑓 (𝑥𝑖 ) + 𝑓 (𝑏)]
8
𝑖=2,5,8,… 𝑖=4,7,10,…
3 ∙ 0.3
ℎ = 0.3, 𝐼(𝑓 ) = [0.5 + 3(0.6 + 0.8 + 2 + 3.2) + 2 ∙ 1.3 + 4.8] = 3.116
8
3 ∙ 0.6
ℎ = 0.6, 𝐼(𝑓 ) = [0.5 + 3(0.8 + 2) + 4.8] = 3.0825
8