2 - CH4 - Numerical - Fall 2023
2 - CH4 - Numerical - Fall 2023
2 - CH4 - Numerical - Fall 2023
Fall 2023
1
~ Truncation Errors and the Taylor Series ~
x3 x5 x7
sin( x) = x − + − +
3! 5! 7!
x2 x3
e = 1+ x +
x
+ +
2! 3!
x2 x3
e = 1+ x +
x
+ +
2! 3!
Taylor’s Theorem
If the function f and its first n+1 derivatives are continuous on an
interval containing 𝑥𝑖 and 𝑥𝑖+1 , then the value of the function at 𝑥𝑖+1
is given by:
Simple form
𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊 h: step size
𝑥=4
ℎ =6−4=2
Example (cont.)
11
Solution: (cont.)
Since the higher order derivatives are zero,
ℎ 2 ℎ 3
𝑓 𝑥 + ℎ = 𝑓 𝑥 + 𝑓′ 𝑥 ℎ + 𝑓″ 𝑥 + 𝑓‴ 𝑥 +⋯
2! 3!
2 3
2 2
𝑓 4 + 2 = 𝑓 4 + 𝑓′ 4 2 + 𝑓″ 4 + 𝑓‴ 4
2! 3!
𝝅
True value of 𝒇 = 𝟎. 𝟓
𝟑
Eng. Muhannad Al-Jabi
Notes
14
We can see that as the step size (h) decreased the Taylor
series becomes more accurate
Example 4.3
Suppose that you have the following function
f ( x) = x m
a) When m=1
b) When m=2
c) When m=3
d) When m=4
Example 4.3: Solution m=1
19
f ( x) = x1
ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!
𝑹𝟎 = 𝒇′(𝝃)(𝒉)
𝑓(2) = 𝑓(1) = 1
𝑹𝟎 = 𝒇′ 𝟏 ∗ 𝟏 = 𝟏
Example 4.3: Solution m=1
20
f ( x) = x1
ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!
First order
𝒇(𝒏+𝟏) (𝝃)
𝑹𝒏 = (𝒉)𝒏+𝟏
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ (𝒏 + 𝟏)!
𝒇(𝟐) (𝝃)
𝑹𝟏 = (𝒉)𝟐
𝑓(2) = 𝑓(1) + 𝑓′(1) ∗ 1 = 2 (𝟐)!
𝒇𝟐 𝟏
𝑹𝟏 = (𝟏)𝟐 = 𝟎
𝟐 ∗𝟏
Example 4.3: Solution m=1
21
f ( x) = x1
ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!
Second order
ℎ 2 𝒇(𝒏+𝟏) (𝝃)
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 𝑹𝒏 = (𝒉)𝒏+𝟏
2! (𝒏 + 𝟏)!
𝒇𝟑 𝟏
𝑓 2 = 𝑓 1 + 𝑓′ 1 ∗ 1 + 0 = 2 𝑹𝟐 = (𝟏)𝟑 = 𝟎
𝟑∗𝟐 ∗𝟏
𝑓(𝑥) = 𝑥 2
ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!
𝑹𝟎 = 𝒇′ 𝟏 ∗ 𝟏 =2
Example 4.3: Solution m=2
23
𝑓(𝑥) = 𝑥 2
ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!
First order
𝒇(𝒏+𝟏) (𝝃)
𝑹𝒏 = (𝒉)𝒏+𝟏
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ (𝒏 + 𝟏)!
𝒇(𝟐) (𝝃)
𝑹𝟏 = (𝒉)𝟐
𝑓 2 = 𝑓 1 + 𝑓′ 1 ∗ 1 (𝟐)!
= 1+2 =3
𝒇𝟐 𝟏
𝑹𝟏 = (𝟏)𝟐 = 𝟏
𝟐 ∗𝟏
Example 4.3: Solution m=2
24
𝑓(𝑥) = 𝑥 2
ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!
Second order
ℎ 2 𝒇(𝒏+𝟏) (𝝃)
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 𝑹𝒏 = (𝒉)𝒏+𝟏
2! (𝒏 + 𝟏)!
1
𝑓 2 = 𝑓 1 + 𝑓′ 1 ∗ 1 + 𝑓″ 1 𝒇𝟑 𝟏
2 𝑹𝟐 = (𝟏)𝟑 = 𝟎
= 1+2(1)+2(0.5) = 4 𝟑∗𝟐 ∗𝟏
So, the second, third and fourth order will give us a result = 4
Example 4.3: Solution m=3
25
f ( x) = x 3
f (2) = f (1) = 1
Zero order
R0 = f ' (1) *1 = 3 *12 = 3
Third order
f ' ' (1) *12 f ' ' ' (1) *13
f (2) = f (1) + f ' (1) *1 + + =8
2 3!
f ' ' ' ' (1) *13 0
R3 = = =0
4! 24
So, when m=4 the fourth order and higher will give us the
true value which is 16
Example
27
ℎ = 1.6 − 1 = 0.6
( 3)
f ' ' (1) f (1)
f (1.6 ) = f (1) + f ' (1)(0.6) + ( 0. 6 ) +
2
( 0. 6 ) 3
2! 3!
Majd Shhadi, PhD
Example: Solution
29
𝒇 𝒙 = 𝒄𝒐𝒔 𝟏 + 𝒙𝟐 + 𝒍𝒐𝒈(𝒙)
Compute the true relative percent error ɛt after each case. Carry
five significant figures during the computation (Show your
complete solution).
′ 2
1
𝑓 𝑥 = −2𝑥𝑠𝑖𝑛 1 + 𝑥 +
𝑥
1
𝑓 ′′ 𝑥 = −4𝑥 2 𝑠𝑖𝑛 1 + 𝑥2 − 2𝑠𝑖𝑛 1 + 𝑥2
− 2
𝑥
2
𝑓 ′′′ 𝑥 = 8𝑥 3 𝑠𝑖𝑛 1 + 𝑥 2 − 12𝑥𝑐𝑜𝑠 1 + 𝑥 2 + 3
𝑥
First: 𝒇 𝟏. 𝟓 = 𝒇 𝟏. 𝟐 + 𝒇′ 𝟏. 𝟐 𝒉
𝒉 𝟐
Second: 𝒇 𝟏. 𝟓 = 𝒇 𝟏. 𝟐 + 𝒇′ 𝟏. 𝟐 𝒉 + 𝒇″ (𝟏. 𝟐)
𝟐!
′ ″ 𝒉𝟐 ‴ 𝒉𝟑
Third: 𝒇 𝟏. 𝟓 = 𝒇 𝟏. 𝟐 + 𝒇 𝟏. 𝟐 𝒉 + 𝒇 (𝟏. 𝟐) +𝒇 (𝟏. 𝟐)
𝟐! 𝟑!
h =1.5-1.2= 0.3
Majd Shhadi, PhD
Example: Solution
32