0% found this document useful (0 votes)
18 views32 pages

2 - CH4 - Numerical - Fall 2023

Uploaded by

sewarasaad21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views32 pages

2 - CH4 - Numerical - Fall 2023

Uploaded by

sewarasaad21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Instructor

Majd Shhadi, PhD

Fall 2023
1
~ Truncation Errors and the Taylor Series ~

The slides’ copyright is to


Eng. Muhannad Al-Jabi & Dr. Aysar Yasin
What is a Taylor series?
3

 Some examples of Taylor series which you must have


seen
x2 x4 x6
cos( x) = 1 − + − +
2! 4! 6!

x3 x5 x7
sin( x) = x − + − +
3! 5! 7!

x2 x3
e = 1+ x +
x
+ +
2! 3!

Majd Shhadi, PhD


What is a Taylor series?
4

x2 x3
e = 1+ x +
x
+ +
2! 3!

The exponential function ex (in blue),


and the sum of the first n + 1 terms
of its Taylor series at 0 (in red).

Majd Shhadi, PhD


General Taylor Series
5

 The general form of the Taylor series is given by


𝑓 ″ 𝑥 𝑓 ‴ 𝑥
𝑓 𝑥 + ℎ = 𝑓 𝑥 + 𝑓′ 𝑥 ℎ + ℎ2 + ℎ3 + ⋯
2! 3!

provided that all derivatives of f(x) are continuous and exist in


the interval [x, x+h]
 In mathematics, a Taylor series is a representation of a
function as an infinite sum of terms that are calculated from
the values of the function’s derivatives at a single point.
 If the Taylor series is centered at zero, then that series is also
called a Maclaurin series.
4.1: The Taylor series
6

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:

where the remainder Rn is defined as

 is some point in the domain [𝒙𝒊 , 𝒙𝒊+𝟏 ]


4.1: The Taylor series
7

Simple form
𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊 h: step size

A remainder term is included to account for all terms from n+1 to


infinity

 is some point in the domain [𝒙𝒊 , 𝒙𝒊+𝟏 ]


4.1: The Taylor series
8

Graphical depiction of a zero-order Taylor series prediction and


remainder.
The Taylor series
9

Using Taylor’s Theorem, we can approximate any


smooth function by a polynomial.

The zero-order approximation of the value of f(x)


is given 𝑓 𝑥𝑖+1 ≈ 𝑓(𝑥𝑖 )

The first-order approximation is given by


𝑓 𝑥𝑖+1 ≈ 𝑓 𝑥𝑖 + 𝑓ሗ (𝑥𝑖 )h

Eng. Muhannad Al-Jabi


Example-Taylor Series
10

 Find the value of 𝒇 𝟔 given that


𝑓 4 = 125, 𝑓 ′ 4 = 74, 𝑓 ″ 4 = 30, 𝑓 ‴ 4 = 6
and all other higher order derivatives of 𝑓 𝑥 at 𝑥 = 4 are
zero
 Solution
ℎ 2 ℎ 3
𝑓 𝑥 + ℎ = 𝑓 𝑥 + 𝑓′ 𝑥 ℎ + 𝑓″ 𝑥 + 𝑓‴ 𝑥 +⋯
2! 3!

𝑥=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!

= 125 + 148 + 60 + 8 = 341

Note that to find 𝑓 6 exactly, we only need the value of the


function and all its derivatives at some other point, in this case 𝒙 = 𝟒
Example 4.2
12

 Use Taylor series expansions with n = 0 to 6 to approximate


f(x) = cos x at xi+1= /3 on the basis of the value of f(x) and
its derivatives at xi = /4.
 Solution
𝜋
h = /3 - /4 = /12 and the true value 𝑓 = 0.5
3

Zero-order approximation: f(/3)  cos (/4) = 0.707106781


0.5 − 0.707106781
𝜀𝑡 = 100% = 41.4%
0.5

First-order approximation: f(/3)  cos (/4) – (/12) sin (/4)


= 0.521986659
Eng. Muhannad Al-Jabi
Example 4.2: Solution
13

Order f(n)(x) Result εt%


0 Cos(x) 0.707106781 41.42
1 -Sin(x) 0.521986659 4.41
2 -Cos(x) 0.497754491 0.45
3 Sin(x) 0.499869147 0.026
4 Cos(x) 0.500007551 0.0015
5 -Sin(x) 0.500000304 6.08E-05
6 -Cos(x) 0.499999988 2.44E-06

𝝅
True value of 𝒇 = 𝟎. 𝟓
𝟑
Eng. Muhannad Al-Jabi
Notes
14

To get more accurate estimation of f(x), we can do one or


both of the following:

 Add more terms to the Taylor polynomial

 Reduce the value of h.

Eng. Muhannad Al-Jabi


Example
15

Use zero-through fourth order Taylor series expansions


for f(x)=ln(x) using the base point at xi =1 to predict
the value of f(x)
1
a) At xi+1= 2.5 f ' ( x) =
x
b) At xi+1 =1.5 1
f ' ' ( x) = −
x2
2
f ' ' ' ( x) =
x3
6
f ' ' ' ' ( x) = −
x4
Example: Solution a
16

True value for ln(2.5) =0.916291


# of order Result εt%
0 0 100
1 1.5 63.70345
2 0.375 59.07414
3 1.5 63.70345
4 0.234375 74.42134
5 ?? ??
Example: Solution b
17

True value for ln(1.5) =0.405465


# of order Result εt
0 0 100
1 0.5 23.31521
2 0.375 7.513596
3 0.416667 2.762672
4 0.401042 1.090929
5 ?? ??

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

Use zero-through fourth order Taylor


series expansions to predict 𝒇(𝟐)
using the base point at xi=1

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!

 Zero order 𝒇(𝒏+𝟏) (𝝃)


𝑹𝒏 = (𝒉)𝒏+𝟏
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 (𝒏 + 𝟏)!

𝑹𝟎 = 𝒇′(𝝃)(𝒉)
𝑓(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 𝑹𝟐 = (𝟏)𝟑 = 𝟎
𝟑∗𝟐 ∗𝟏

So , the result of third and fourth order will be 2.


Example 4.3: Solution m=2
22

𝑓(𝑥) = 𝑥 2

ℎ 2 ℎ 3
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + 𝑓 ″ 𝑥 + 𝑓 ‴ 𝑥𝑖 +⋯
2! 3!

 Zero order 𝒇(𝒏+𝟏) (𝝃)


𝑹𝒏 = (𝒉)𝒏+𝟏
𝑓 𝑥𝑖+1 = 𝑓 𝑥𝑖 (𝒏 + 𝟏)!
𝑓(2) = 𝑓(1) = 1
𝑹𝟎 = 𝒇′(𝝃)(𝒉)

𝑹𝟎 = 𝒇′ 𝟏 ∗ 𝟏 =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

 First order f (2) = f (1) + f ' (1) *1 = 4


f ' ' (1) *12 6
R1 = = =3
2 2

 Second order f (2) = f (1) + f ' (1) *1 +


f ' ' (1) *12
=7
2
f ' ' ' (1) *13 6
R2 = = =1
3! 6
Example 4.3: Solution m=3
26

 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, the third and fourth order will give us a result =8

So, when m=4 the fourth order and higher will give us the
true value which is 16
Example
27

 Use first-through third-order Taylor series to predict


𝑓(1.6) for:
𝒇 𝒙 = 𝒔𝒊𝒏𝒙 + 𝒄𝒐𝒔 𝟏 + 𝒙𝟐 − 𝟏

 Use base point at x=1. Compute the true percent


relative error ɛt for each approximation.

Majd Shhadi, PhD


Example: Solution
28

 Use first-through third-order Taylor series to predict


𝑓(1.6) for:
𝒇 𝒙 = 𝒔𝒊𝒏(𝒙) + 𝒄𝒐𝒔 𝟏 + 𝒙𝟐 − 𝟏

 Use base point at x=1. Compute the true percent


relative error ɛt for each approximation.

ℎ = 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

True value f(1.6)= -0.91416

Order f(n)(x) f(n)(1) Sum εt%

0 𝑠𝑖𝑛(𝑥) + 𝑐𝑜𝑠 1 + 𝑥 2 − 1 -0.57468 -0.57468 37.13

1 cos(𝑥) − 2𝑥𝑠𝑖𝑛 1 + 𝑥 2 -1.2782 -1.3417 46.75


-𝑠𝑖𝑛(𝑥) − 4𝑥 2 𝑐𝑜𝑠 1 + 𝑥 2
2 -0.99548 -1.5208 66.34
− 2𝑠𝑖𝑛 1 + 𝑥 2
-cos 𝑥 − 12𝑥𝑐𝑜𝑠 1 + 𝑥 2
11.7278 -1.0986 20.17
3 + 8𝑥 3 𝑠𝑖𝑛 1 + 𝑥 2

Majd Shhadi, PhD


Example
30

 Use first to third order Taylor series expansion to find 𝑓(1.5)


with 𝑥0 = 1.2 as a base point for the following function:

𝒇 𝒙 = 𝒄𝒐𝒔 𝟏 + 𝒙𝟐 + 𝒍𝒐𝒈(𝒙)

Compute the true relative percent error ɛt after each case. Carry
five significant figures during the computation (Show your
complete solution).

Majd Shhadi, PhD


Example: Solution
31

′ 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

True value f(1.5)= -0.818038

Order xi fn(xi) f(xi+1) εt%

0 1.2 -0.68463 -0.68463 16.31

1 1.2 -0.71571 -0.89935 9.94

2 1.2 2.41426 -0.79071 3.34

3 1.2 21.07884 -0.69585 14.94

Majd Shhadi, PhD

You might also like