You are on page 1of 17

ES-341:

Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Numerical
Methods for
Initial Value
Problem
ES-341: Numerical Analysis
Euler Method for
solving Initial Value
Problem

Dr. Mazhar Ali


Mehboob ul Haq (TA)

Faculty of Engineering Sciences

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology

14th May 2022

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 1 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Numerical
Methods for
Initial Value
Problem
Euler Method for
solving Initial Value
Problem

1 Numerical Methods for Initial Value Problem


Euler Method for solving Initial Value Problem

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 2 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Numerical
Methods for
Initial Value
Problem
Euler Method for
solving Initial Value
Problem

Numerical Methods for Initial Value Problem

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 3 / 17
ES-341:
Numerical General form of an Ordinary Differential Equation (ODE)
Analysis

Dr. Mazhar Ali An Ordinary Differential (ODE) is a differential equations which


Mehboob ul Haq
(TA) involves the derivatives of one variable dependent functions i.e.,
Numerical
y (x), g (x), f (x), . . . with respect to an independent variable x.
Methods for
Initial Value
Problem
y ′ = f (x, y )
Euler Method for
solving Initial Value
Problem

Geometrical meaning
Let y1 (x) is the solution of the O.D.E. y ′ = f (x, y ).
𝒚𝟏 (𝒙) → solution of ODE is the integral curve 𝒚′ = 𝒇(𝒙, 𝒚) → represents
the directional field.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 4 / 17
ES-341:
Numerical
Analysis
Initial Value Problem (IVP)
Dr. Mazhar Ali
Mehboob ul Haq
(TA) Let us consider an Initial Value Problem (IVP) as,
Numerical
Methods for dy
Initial Value = f (t, y ); a ≤ t ≤ b; y (a) = α
Problem
dt
Euler Method for
solving Initial Value
Problem

The solution for this IVP can be stated as,

y (t), a≤t≤b

Here, we consider a numerical method for solving IVP, referred to


as “Euler Method”. It obtains an approximation on the well-posed
IVP.
Euler Method obtains discrete approximations of the solution y (t)
at discrete/finite steps ti = {t0 , t1 , . . . , tn }, i = 1, 2, . . . , n.
Defined as,

tn − t0
ti+i = ti + h, i = 0, 1, . . . , n; h=
n

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 5 / 17
ES-341:
Numerical
Analysis Derivation: Euler Method
Dr. Mazhar Ali
Mehboob ul Haq Let us consider y (t) is the unique solution to the IVP, and has two
(TA)
continuous derivatives on [a, b]. so that for each
Numerical
Methods for
i = 0, 1, . . . , n − 1. We can expand yi using first order Taylor
Initial Value
Problem
series as,
Euler Method for
solving Initial Value
∆ti ′′
Problem
y (ti+1 ) = y (ti ) + y ′ (ti )∆ti +
y (ξi )
2!
 
Here ∆ti = ti+1 − ti = h. And y ′ (ti ) = f ti , y (ti ) .

  ∆t
i ′′
y (ti+1 ) = y (ti ) + h f ti , y (ti ) + y (ξi )
2!
Hence, we can approximate,
 
y (ti+1 ) ≈ y (ti ) + h f ti , y (ti )

yi+1 ≈ yi + h f (ti , yi )

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 6 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)
Euler Algorithm
Numerical
Methods for Start with t0 = α, tn = β
Initial Value
Problem Define step size h = (tn − t0 )/n, discretization of interval [α, β]
Euler Method for
solving Initial Value into n steps.
Problem  
Define slope/function f t, y (t) .
Define y (t0 ) = α.
Start iteration counter k = 0 : 1 : n
1 Calculate ti = t0 + k(h)
2 Define yi =y (ti ) 
3 Calculate f ti , yi
4 Calculate yi+1 ≈ yi + h f (ti , yi )
end counter

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 7 / 17
ES-341:
Numerical
Analysis Example 1: Initial Value Problem (IVP)
Dr. Mazhar Ali
Mehboob ul Haq Let us consider an Initial Value Problem (IVP) as,
(TA)

Numerical
Methods for
y ′ = y − t 2 + 1; 0 ≤ t ≤ 2; y (0) = 0.5
Initial Value
Problem
Euler Method for
solving Initial Value
consider step size h = 0.5.
Problem

Solution
First we identify t0 = 0 and tn = 2
We can describe number of discrete steps as
n = (tn − t0 )/h = (2 − 0)/0.5 = 4. Hence, ti = {t0 , t1 , t2 , t3 , t4 }.
We can describe ti+1 = ti + i(h), i = 0, 1, 2, 3, 4.
ti yi = y (ti )
t0 = 0 y0 = 0.5
t1 = 0.5 y1
t2 = 1.0 y2
t3 = 1.5 y3
t4 = 2.0 y4

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 8 / 17
ES-341:
Numerical
Analysis
Iteration 1:
Dr. Mazhar Ali
Mehboob ul Haq t0 = 0, y0 = y (t0 ) = 0.5
(TA)
f (t0 , y0 ) = y0 − t02 + 1 = (0.5) − (0)2 + 1 = 1.5
Numerical
Methods for
Initial Value
Problem
y1 ≈ y0 + hf (t0 , y0 ) = 0.5 + 0.5(1.5) = 1.25
Euler Method for
solving Initial Value
Problem
Iteration 2:
t1 = 0.5, y1 = y (t1 ) = 1.25
f (t1 , y1 ) = y1 − t12 + 1 = (1.25) − (0.5)2 + 1 = 1.5

y2 ≈ y1 + hf (t1 , y1 ) = 1.25 + 0.5(1.5) = 2.25

Iteration 3:
t2 = 1.0, y2 = y (t2 ) = 2.25
f (t2 , y2 ) = y2 − t22 + 1 = (2.25) − (1.0)2 + 1 = 2.25

y3 ≈ y2 + hf (t2 , y2 ) = 2.25 + 0.5(2.25) = 3.375

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 9 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)
Iteration 4:
Numerical
Methods for
Initial Value
t3 = 1.5, y3 = y (t3 ) = 3.375
Problem
Euler Method for f (t3 , y3 ) = y3 − t32 + 1 = (3.375) − (1.5)2 + 1 = 2.125
solving Initial Value
Problem

y4 ≈ y3 + hf (t3 , y3 ) = 3.375 + 0.5(2.125) = 4.4375

ti yi = y (ti )
t0 = 0 y0 = 0.5
t1 = 0.5 y1 = 1.25
t2 = 1.0 y2 = 2.25
t3 = 1.5 y3 = 3.375
t4 = 2.0 y4 = 4.4375

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 10 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Example 2: Initial Value Problem (IVP)
(TA)
Let us consider an Initial Value Problem (IVP) as,
Numerical
Methods for
Initial Value
Problem y ′ = 2 − e −4t − 2y ; 0 ≤ t ≤ 0.5; y (0) = 1.0
Euler Method for
solving Initial Value
Problem
consider step size h = 0.1
The exact solution is ŷ (t) = 1 + 21 e −4t − 12 e −2t , also calculate
relative error.

Solution
First we identify t0 = 0 and tn = 0.5
We can describe number of discrete steps as
n = (tn − t0 )/h = (0.5 − 0)/0.1 = 5.
Hence, ti = {t0 , t1 , t2 , t3 , t4 , t5 }.
We can describe ti+1 = ti + i(h), i = 0, 1, 2, 3, 4, 5.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 11 / 17
ES-341:
Numerical
Analysis ti yi = y (ti )
Dr. Mazhar Ali t0 = 0 y0 = 1.0
Mehboob ul Haq
(TA) t1 = 0.1 y1
Numerical
t2 = 0.2 y2
Methods for
Initial Value
t3 = 0.3 y3
Problem
t4 = 0.4 y4
Euler Method for
solving Initial Value
Problem
t5 = 0.5 y5

Iteration 1:
t0 = 0, y0 = y (t0 ) = 1.0
−4t0
f (t0 , y0 ) = 2 − e − 2y0 = 2 − e 0 − 2(1.0) = −1

y1 ≈ y0 + hf (t0 , y0 ) = 1.0 + 0.1(−1) = 0.900000


1 1
ŷ (t1 ) = ŷ1 = 1 + e −4t1 − e −2t1
2 2
1 1
ŷ1 = 1 + e −4(0.1) − e −2(0.1) = 0.925795
2 2
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 12 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali ŷ − y


Mehboob ul Haq 1 1
(TA) Relative Error = × 100 =
ŷ1
Numerical 0.925795 − 0.9
Methods for
× 100 = 2.79%

Initial Value
0.9257945

Problem
Euler Method for
solving Initial Value
Problem

Iteration 2:

t1 = 0.1, y1 = y (t1 ) = 0.9


−4t1
f (t1 , y1 ) = 2 − e − 2y1 = 2 − e −4(0.1) − 2(0.9) = −0.470320

y2 ≈ y1 + hf (t1 , y1 ) = 0.9 + 0.1(−0.470320) = 0.852968


1 1
ŷ (t2 ) = ŷ2 = 1 + e −4t2 − e −2t2
2 2
1 1
ŷ2 = 1 + e −4(0.2) − e −2(0.2) = 0.889504
2 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 13 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali ŷ − y


Mehboob ul Haq 2 2
(TA) Relative Error = × 100 =
ŷ2
Numerical 0.889504 − 0.852968
Methods for
× 100 = 4.11%

Initial Value
0.889504

Problem
Euler Method for
solving Initial Value
Problem

Iteration 3:

t2 = 0.2, y2 = y (t2 ) = 0.852968


−4t2
f (t2 , y2 ) = 2 − e − 2y2 = 2 − e −4(0.2) − 2(0.852968) = −0.155265

y3 ≈ y2 + hf (t2 , y2 ) = 0.852968 + 0.1(−0.155265) = 0.8374415


1 1
ŷ (t3 ) = ŷ3 = 1 + e −4t3 − e −2t3
2 2
1 1
ŷ3 = 1 + e −4(0.3) − e −2(0.3) = 0.87619128
2 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 14 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali ŷ − y


Mehboob ul Haq 3 3
(TA) Relative Error = × 100 =
ŷ3
Numerical 0.87619128 − 0.8374415
Methods for
× 100 = 4.42%

Initial Value
0.87619128

Problem
Euler Method for
solving Initial Value
Problem

Iteration 4:

t3 = 0.3, y3 = y (t3 ) = 0.8374415


−4t3
f (t3 , y3 ) = 2 − e − 2y3 = 2 − e −4(0.3) − 2(0.8374415) = 0.023923

y4 ≈ y3 + hf (t3 , y3 ) = 0.8374415 + 0.1(0.023923) = 0.8398338


1 1
ŷ (t4 ) = ŷ4 = 1 + e −4t4 − e −2t4
2 2
1 1
ŷ4 = 1 + e −4(0.4) − e −2(0.4) = 0.876284
2 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 15 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali ŷ − y


Mehboob ul Haq 4 4
(TA) Relative Error = × 100 =
ŷ4
Numerical 0.876284 − 0.8398338
Methods for
× 100 = 4.16%

Initial Value
0.876284

Problem
Euler Method for
solving Initial Value
Problem

Iteration 5:

t4 = 0.4, y4 = y (t4 ) = 0.8398338


−4t4
f (t4 , y4 ) = 2 − e − 2y4 = 2 − e −4(0.4) − 2(0.8398338) = 0.118435

y5 ≈ y4 + hf (t4 , y4 ) = 0.8398338 + 0.1(118435) = 0.8516773


1 1
ŷ (t5 ) = ŷ5 = 1 + e −4t5 − e −2t5
2 2
1 1
ŷ5 = 1 + e −4(0.5) − e −2(0.5) = 0.883728
2 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 16 / 17
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Numerical
Methods for
Initial Value
Problem
Euler Method for
solving Initial Value
Problem
ŷ − y
5 5
Relative Error = × 100 =
ŷ5
0.883728 − 0.8516773
× 100 = 3.63%

0.883728

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 14th May 2022 17 / 17

You might also like