ES-341: Numerical Analysis: Dr. Mazhar Ali Mehboob Ul Haq (TA)
ES-341: Numerical Analysis: Dr. Mazhar Ali Mehboob Ul Haq (TA)
Numerical
Analysis
Numerical
Methods for
Initial Value
Problem
ES-341: Numerical Analysis
Runge Kutta 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) 20th May 2022 1 / 12
ES-341:
Numerical
Analysis
Numerical
Methods for
Initial Value
Problem
Runge Kutta 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) 20th May 2022 2 / 12
ES-341:
Numerical
Analysis
Numerical
Methods for
Initial Value
Problem
Runge Kutta 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) 20th May 2022 3 / 12
ES-341:
Numerical General form of an Ordinary Differential Equation (ODE)
Analysis
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) 20th May 2022 4 / 12
ES-341:
Numerical
Analysis Initial Value Problem (IVP)
Dr. Mazhar Ali
Mehboob ul Haq Let us consider an Initial Value Problem (IVP) as,
(TA)
Numerical dy
Methods for
Initial Value
= f (t, y ); a ≤ t ≤ b; y (a) = α
Problem dt
Runge Kutta Method
for solving Initial
Value Problem
The solution for this IVP can be stated as,
y (t), a≤t≤b
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) 20th May 2022 5 / 12
ES-341:
Numerical
Analysis
Derivation: Runge Kutta Method
Dr. Mazhar Ali
Mehboob ul Haq
(TA) Let us consider y (t) is the unique solution to the IVP, expanding
this up to the second order Taylor series,
Numerical
Methods for
Initial Value
h2 ′′
Problem
y (t + h) = y (t) + hy ′ (t) + y (t) + O(h3 )
Runge Kutta Method
for solving Initial 2
Value Problem
b−a
Here h is the step size i.e., h = n .
h2
y (t + h) = y (t) + hf (t, y ) + ft (t, y ) + fy (t, y )y ′ (t) + O(h3 )
2
h
y (t + h) = y (t) + f (t, y )
2
hh i
+ f (t, y ) + hft (t, y ) + hfy (t, y )f (t, y ) + O(h3 )
2
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20th May 2022 6 / 12
ES-341:
Numerical
Analysis
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20th May 2022 7 / 12
ES-341:
Numerical
Analysis
Numerical
Methods for
Initial Value
Problem We can finalize algorithm as,
Runge Kutta Method
for solving Initial
Value Problem
h
yi+1 = yi + (k1 + k2 )
2
k1 = f (ti , yi )
k2 = f ti + h, yi + hk1
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20th May 2022 8 / 12
ES-341:
Numerical
Analysis
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20th May 2022 9 / 12
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
Runge Kutta Method
for solving Initial
consider step size h = 0.5.
Value 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) 20th May 2022 10 / 12
ES-341:
Numerical
Analysis
Iteration 1:
Dr. Mazhar Ali
Mehboob ul Haq t0 = 0, y0 = y (t0 ) = 0.5
(TA)
k1 = f (t0 , y0 ) = y0 − t02 + 1 = (0.5) − (0)2 + 1 = 1.5
Numerical
Methods for
Initial Value t0 + h = 0.5, y0 + h(k1 ) = 0.5 + 0.5(1.5) = 1.2500
Problem
Runge Kutta Method
for solving Initial k2 = f (t0 + h, y0 + hk1 ) = (1.25) − (0.5)2 + 1 = 2
Value Problem
h
y1 ≈ y0 + (k1 + k2 ) = 1.3750
2
Iteration 2:
t1 = 0.5, y1 = y (t1 ) = 1.375
k1 = f (t1 , y1 ) = y1 − t12 + 1 = (1.375) − (0.5)2 + 1 = 2.1250
t1 + h = 1.0, y1 + h(k1 ) = 1.375 + 0.5(2.1250) = 2.4375
k2 = f (t1 + h, y1 + hk1 ) = (2.4375) − (1.0)2 + 1 = 2.4375
h
y2 ≈ y1 + (k1 + k2 ) = 2.5156
2
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20th May 2022 11 / 12
ES-341:
Numerical Iteration 3:
Analysis
h
y3 ≈ y2 + (k1 + k2 ) = 3.7754
2
Iteration 4:
t3 = 1.5, y3 = y (t3 ) = 3.7754
k1 = f (t3 , y3 ) = y3 − t32 + 1 = (3.7754) − (1.5)2 + 1 = 2.5254
t3 + h = 2.0, y3 + h(k1 ) = 3.7754 + 0.5(2.5254) = 6.1790
k2 = f (t3 + h, y3 + hk1 ) = (6.1790) − (2.0)2 + 1 = 2.0381
h
y4 ≈ y3 + (k1 + k2 ) = 4.9163
2
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20th May 2022 12 / 12