0% found this document useful (0 votes)
15 views

Ordinary Differential Equations

Uploaded by

mo.dmour22
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Ordinary Differential Equations

Uploaded by

mo.dmour22
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

College of Engineering, Department of Mechanical Engineering

Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Ordinary Differential Equations (ODEs)


ODE ≡ Ordinary Differential Equation
 Dependent variable is a function of only one independent variable: time,
or one space dimension.
𝒅𝒚
= 𝒇(𝒙, 𝒚)
𝒅𝒙
 Order of the ODE: Highest derivative appearing in the ODE
𝒅𝟐 𝒚 𝒅𝒚
+ 𝒚 +𝟓=𝟎 ∶ 𝟐𝒏𝒅 𝒐𝒓𝒅𝒆𝒓 𝑶𝑫𝑬
𝒅𝒙𝟐 𝒅𝒙
𝒅𝟑 𝒚 𝟐
𝒅𝒚
+ 𝒚 +𝒚=𝟎 ∶ 𝟑𝒓𝒅 𝒐𝒓𝒅𝒆𝒓 𝑶𝑫𝑬
𝒅𝒙𝟑 𝒅𝒙
 Linear/non-linear ODE:
𝒅𝟐 𝒚 𝒅𝒚
+ 𝒚 +𝟓=𝟎 ∶ 𝒏𝒐𝒏𝒍𝒊𝒏𝒆𝒂𝒓
𝒅𝒙𝟐 𝒅𝒙
𝒅𝟑 𝒚 𝟐
𝒅𝒚
+ 𝒙 + 𝒙𝒚 = 𝟎 ∶ 𝒍𝒊𝒏𝒆𝒂𝒓
𝒅𝒙𝟑 𝒅𝒙
 Initial value problems/Boundary value problems
𝒅𝒚
= 𝒇(𝒕, 𝒚), 𝒕 𝒊𝒔 𝒕𝒊𝒎𝒆: 𝑰𝒏𝒊𝒕𝒊𝒂𝒍 𝒗𝒂𝒍𝒖𝒆 𝒑𝒓𝒐𝒃𝒍𝒆𝒎
𝒅𝒕
𝒅𝟐 𝒚
= 𝒇(𝒙, 𝒚), 𝒙 𝒊𝒔 𝒂 𝒔𝒑𝒂𝒄𝒆 𝒅𝒊𝒎𝒆𝒏𝒔𝒊𝒐𝒏: 𝒃𝒐𝒖𝒏𝒅𝒂𝒓𝒚 𝒗𝒂𝒍𝒖𝒆 𝒑𝒓𝒐𝒃𝒍𝒆𝒎
𝒅𝒙𝟐

Page 1 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Numerical Solution of ODEs


Typical System:
𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐 , 𝑭𝒊𝒏𝒅 𝒚(𝒙) 𝒏𝒖𝒎𝒆𝒓𝒊𝒄𝒂𝒍𝒍𝒚
𝒅𝒙
1. The Taylor Series Method:
Expand 𝒚(𝒙) about 𝒙𝒐 :

𝒉𝟐 ′′ 𝒉𝟑 ′′′ 𝒉𝟒 (𝟒)
𝒚(𝒙) = 𝒚(𝒙𝒐 ) + 𝒉𝒚′ (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + ⋯
𝟐 𝟑! 𝟒!
Example
Use the Taylor series method to numerically integrate
𝒅𝒚
= −𝟐𝒙 − 𝒚, 𝒚(𝟎) = −𝟏
𝒅𝒙

The exact solution is:


𝒚(𝒙) = −𝟑𝒆−𝒙 − 𝟐𝒙 + 𝟐
Solution:
𝒙𝒐 = 𝟎
𝒚′ (𝒙) = −𝟐𝒙 − 𝒚, → 𝒚′ (𝒙𝒐 ) = −𝟐𝒙𝒐 − 𝒚(𝒙𝒐 )
𝒚′ (𝟎) = −𝟐(𝟎) − 𝒚(𝟎) = 𝟎 − (−𝟏) = 𝟏

𝒚′′ (𝒙) = −𝟐 − 𝒚′ , → 𝒚′′ (𝒙𝒐 ) = −𝟐 − 𝒚′ (𝒙𝒐 )


𝒚′′ (𝟎) = −𝟐 − 𝒚′ (𝟎) = −𝟐 − 𝟏 = −𝟑
𝒚′′′ (𝒙) = −𝒚′′ , → 𝒚′′′ (𝒙𝒐 ) = −𝒚′′ (𝒙𝒐 )
𝒚′′′ (𝟎) = −𝒚′′ (𝟎) = 𝟑

𝒚(𝟒) (𝒙) = −𝒚′′′ , → 𝒚(𝟒) (𝒙𝒐 ) = −𝒚′′′ (𝒙𝒐 )


𝒚(𝟒) (𝟎) = −𝒚′′′ (𝟎) = −𝟑
Substitute in Taylor series:
𝟑 𝟏 𝟑 𝟑
𝒚(𝒙) = −𝟏 + 𝒉 − 𝒉𝟐 + 𝒉𝟑 − 𝒉 + 𝒆𝒓𝒓𝒐𝒓
𝟐 𝟐 𝟐𝟒

Page 2 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Using above equation, numerical solution is computed and compared with the
exact solution, shown in the table below:
𝒙 0 0.1 0.2 0.3 0.4 0.5
𝒚𝒏𝒖𝒎 -1.00 -0.91451 -0.85620 -0.82251 -0.81120 -0.82031
𝒚𝒆𝒙𝒂𝒄𝒕 -1.00 -0.91451 -0.85619 -0.82245 -0.81096 -0.81959

Solution is good with small h, also not practical for different reasons.

Runge – Kutta Methods


Euler’s Method
To numerically solve:

𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐
𝒅𝒙
Taylor series:
𝒉𝟐 ′′ 𝒉𝟑 ′′′ 𝒉𝟒 (𝟒)
𝒚(𝒙) = 𝒚(𝒙𝒐 ) + 𝒉𝒚′ (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + ⋯
𝟐 𝟑! 𝟒!
𝒉 = 𝒙 − 𝒙𝒐

In the Euler’s method: we take the first two terms of the Taylor series:
𝒚(𝒙) = 𝒚(𝒙𝒐 ) + 𝒉𝒚′ (𝒙𝒐 ) + 𝑶(𝒉𝟐 )

OR:
𝒚(𝒙) = 𝒚(𝒙𝒐 ) + 𝒉𝒇(𝒙𝒐 , 𝒚𝒐 ) + 𝑶(𝒉𝟐 )

𝑵𝒐𝒕𝒆 𝒕𝒉𝒂𝒕 𝒚′ (𝒙𝒐 ) = 𝒇(𝒙𝒐 , 𝒚𝒐 ) 𝒊𝒔 𝒕𝒉𝒆 𝒔𝒍𝒐𝒑𝒆 𝒐𝒇 𝒚(𝒙) 𝒂𝒕 (𝒙𝒐 , 𝒚𝒐 ); estimation of the
slope for the whole interval h, is determined at the initial point only.
Since
𝒙 = 𝒙𝒐 + 𝒉
OR:
𝒙𝒊+𝟏 = 𝒙𝒊 + 𝒉

Page 3 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Above equation can be re-written as:


𝒚(𝒙𝒊+𝟏 ) = 𝒚(𝒙𝒊 ) + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝑶(𝒉𝟐 )
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝑶(𝒉𝟐 )
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 + 𝑶(𝒉𝟐 )

Euler Scheme
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )

To find 𝒚𝒊+𝟏 : we need 𝒚𝒊 , 𝒚′𝒊

Euler’s method.

Example:
Use Euler’s method to numerically integrate
𝒅𝒚
= −𝟐𝒙 − 𝒚 = 𝒇(𝒙, 𝒚), 𝒚(𝟎) = −𝟏
𝒅𝒙

from 𝒙 = 𝟎 to 𝒙 = 𝟎. 𝟓 with a step size of 0.1


Solution:
𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊

𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 + 𝑶(𝒉𝟐 )

Page 4 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒊 = 𝟎: 𝒙𝒐 = 𝟎, 𝒚(𝟎) = −𝟏, 𝒚′ (𝟎) = −𝟐(𝟎) − 𝒚(𝟎) = 𝟎 − (−𝟏) = 𝟏


𝒊 = 𝟏: 𝒙𝟏 = 𝟎. 𝟏, 𝒚𝟏 = 𝒚𝒐 + 𝒉𝒚′𝒐 = −𝟏 + (𝟎. 𝟏)(𝟏) = −𝟎. 𝟗
𝒚′𝟏 = −𝟐𝒙𝟏 − 𝒚𝟏 = −𝟐(𝟎. 𝟏) − (−𝟎. 𝟗) = 𝟎. 𝟕

𝒊 = 𝟐: 𝒙𝟐 = 𝟎. 𝟐, 𝒚𝟐 = 𝒚𝟏 + 𝒉𝒚′𝟏 = −𝟎. 𝟗 + (𝟎. 𝟏)(𝟎. 𝟕) = −𝟎. 𝟖𝟑


𝒚′𝟐 = −𝟐𝒙𝟐 − 𝒚𝟐 = −𝟐(𝟎. 𝟐) − (−𝟎. 𝟖𝟑) = 𝟎. 𝟒𝟑
𝒊 = 𝟑: 𝒙𝟑 = 𝟎. 𝟑, 𝒚𝟑 = 𝒚𝟐 + 𝒉𝒚′𝟐 = −𝟎. 𝟖𝟑 + (𝟎. 𝟏)(𝟎. 𝟒𝟑) = −𝟎. 𝟕𝟖𝟕𝟎
𝒚′𝟑 = −𝟐𝒙𝟑 − 𝒚𝟑 = −𝟐(𝟎. 𝟑) − (−𝟎. 𝟕𝟖𝟕𝟎) = 𝟎. 𝟏𝟖𝟕𝟎
𝒊 = 𝟒: 𝒙𝟒 = 𝟎. 𝟒, 𝒚𝟒 = 𝒚𝟑 + 𝒉𝒚′𝟑 = −𝟎. 𝟕𝟖𝟕 + (𝟎. 𝟏)(𝟎. 𝟏𝟖𝟕) = −𝟎. 𝟕𝟔𝟖𝟑
𝒚′𝟒 = −𝟐𝒙𝟒 − 𝒚𝟒 = −𝟐(𝟎. 𝟒) − (−𝟎. 𝟕𝟔𝟖𝟑) = −𝟎. 𝟎𝟑𝟏𝟕
𝒊 = 𝟓: 𝒙𝟓 = 𝟎. 𝟓, 𝒚𝟓 = 𝒚𝟒 + 𝒉𝒚′𝟒 = −𝟎. 𝟕𝟔𝟖𝟑 + (𝟎. 𝟏)(−𝟎. 𝟎𝟑𝟏𝟕) = −𝟎. 𝟕𝟕𝟏𝟒𝟕
Solution Summary
𝒊 𝒙 𝒚𝒏𝒖𝒎 𝒚𝒆𝒙𝒂𝒄𝒕 Error % 𝑬𝒓𝒓𝒐𝒓
0 0 -1.00000 -1.00000 0.00000 0
1 0.1 -0.90000 -0.91451 0.01451 1.59
2 0.2 -0.83000 -0.85619 0.02619 3.06
3 0.3 -0.78700 -0.82245 0.03545 4.31
4 0.4 -0.76830 -0.81096 0.04266 5.26
5 0.5 -0.77147 -0.81959 0.04812 5.87
Error increases as the solution evolves. why?

Page 5 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Heun’s Method
To numerically solve:

𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐
𝒅𝒙
In Euler’s method: Slope is taken at the starting point 𝒙𝒊 :
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉. 𝒔𝒍𝒐𝒑𝒆 (𝟏)
To improve the estimate of the slope:
Determine the slope at the starting and end points; 𝒚′𝒊 , 𝒚′𝒊+𝟏
𝟏 ′
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒔𝒍𝒐𝒑𝒆 = (𝒚𝒊 + 𝒚′𝒊+𝟏 ) (𝟐)
𝟐
From (1) & (2):
𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + . (𝒚′𝒊 + 𝒚′𝒊+𝟏 ) (𝟑)
𝟐
Equation (3) is equivalent to adding one more term in Euler’s formula. To see
this:
Taylor series:
𝒉𝟐 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 + 𝒚𝒊 + ⋯
𝟐
𝒉𝟐 𝒚′𝒊+𝟏 − 𝒚′𝒊
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 + [ ]+⋯
𝟐 𝒉
𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 + 𝒉[𝒚′𝒊+𝟏 − 𝒚′𝒊 ] + ⋯
𝟐
𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉[𝒚′𝒊 + 𝒚′𝒊+𝟏 ] (𝟑)
𝟐
OR:
𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉[𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 )]
𝟐
One problem with (3):
𝒚′𝒊+𝟏 = 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 ) 𝒊𝒔 𝒖𝒏𝒌𝒏𝒐𝒘𝒏.
To overcome this problem:
If 𝒚𝒊+𝟏 is known  we can find 𝒚′𝒊+𝟏 from 𝒚′𝒊+𝟏 = 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 )
Page 6 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

From Euler’s formula:


𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊
 Use Euler’s formula to “Predict” a value for 𝒚𝒊+𝟏 , from which
𝒚′𝒊+𝟏 = 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 ) can be calculated, then use this value in (3) to
“Correct” 𝒚𝒊+𝟏
 Heun’s method is concluded as:

Predictor:
̅𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒚
→ ̅′𝒊+𝟏 = 𝒇(𝒙𝒊+𝟏 , 𝒚
𝒚 ̅𝒊+𝟏 )
Corrector
𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉[𝒚′𝒊 + 𝒚
̅′𝒊+𝟏 ] = 𝒚𝒊 + 𝒉[𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊+𝟏 , 𝒚
̅𝒊+𝟏 )] (𝟒)
𝟐 𝟐

Page 7 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

̅𝒊+𝟏 in (4):
Substitute for 𝒙𝒊+𝟏 , 𝒚

𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + [ 𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ))] 𝒉 (𝟓)
𝟐 𝟐

Example:
Use Heun’s method to numerically integrate
𝒅𝒚
= −𝟐𝒙 − 𝒚 = 𝒇(𝒙, 𝒚), 𝒚(𝟎) = −𝟏
𝒅𝒙

from 𝒙 = 𝟎 to 𝒙 = 𝟎. 𝟓 with a step size of 𝒉 = 𝟎. 𝟏


Solution
𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊
Predictor:
̅𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒚
̅′𝒊+𝟏 = 𝒇(𝒙𝒊+𝟏 , 𝒚
𝒚 ̅𝒊+𝟏 )
Corrector
𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉[𝒚′𝒊 + 𝒚
̅′𝒊+𝟏 ] = 𝒚𝒊 + 𝒉[𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊+𝟏 , 𝒚
̅𝒊+𝟏 )]
𝟐 𝟐
𝒊 = 𝟎: 𝒙𝒐 = 𝟎,
𝒚𝒐 = 𝒚(𝟎) = −𝟏, 𝒚′𝒐 = 𝒚′ (𝟎) = −𝟐(𝟎) − 𝒚(𝟎) = 𝟎 − (−𝟏) = 𝟏
𝒊 = 𝟏: 𝒙𝟏 = 𝟎. 𝟏
̅𝟏 = 𝒚𝒐 + 𝒉𝒚′𝒐 = −𝟏 + (𝟎. 𝟏)(𝟏) = −𝟎. 𝟗
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟏 = 𝒇(𝒙𝟏 , 𝒚
𝒚 ̅𝟏 ) = −𝟐𝒙𝟏 − 𝒚
̅𝟏 = −𝟐(𝟎. 𝟏) − (−𝟎. 𝟗) = 𝟎. 𝟕
𝒉 ′ 𝟎. 𝟏
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟏 = 𝒚𝒐 + ̅′𝟏 ] = −𝟏 +
[𝒚𝒐 + 𝒚 [𝟏 + 𝟎. 𝟕] = −𝟎. 𝟗𝟏𝟓
𝟐 𝟐
𝒚′𝟏 = −𝟐𝒙𝟏 − 𝒚𝟏 = −𝟐(𝟎. 𝟏) − (−𝟎. 𝟗𝟏𝟓𝟎) = 𝟎. 𝟕𝟏𝟓
𝒊 = 𝟐: 𝒙𝟐 = 𝟎. 𝟐
̅𝟐 = 𝒚𝟏 + 𝒉𝒚′𝟏 = −𝟎. 𝟗𝟏𝟓 + (𝟎. 𝟏)(𝟎. 𝟕𝟏𝟓) = −𝟎. 𝟖𝟒𝟑𝟓
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟐 = 𝒇(𝒙𝟐 , 𝒚
𝒚 ̅𝟐 ) = −𝟐𝒙𝟐 − 𝒚
̅𝟐 = −𝟐(𝟎. 𝟐) − (−𝟎. 𝟖𝟒𝟑𝟓) = 𝟎. 𝟒𝟒𝟑𝟓
𝒉 ′ 𝟎. 𝟏
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟐 = 𝒚𝟏 + ̅′𝟐 ] = −𝟎. 𝟗𝟏𝟓 +
[𝒚𝟏 + 𝒚 [𝟎. 𝟕𝟏𝟓 + 𝟎. 𝟒𝟒𝟑𝟓] = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓
𝟐 𝟐
𝒚′𝟐 = −𝟐𝒙𝟐 − 𝒚𝟐 = −𝟐(𝟎. 𝟐) − (−𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓) = 𝟎. 𝟒𝟓𝟕𝟎𝟕𝟓

Page 8 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒊 = 𝟑: 𝒙𝟑 = 𝟎. 𝟑
̅𝟑 = 𝒚𝟐 + 𝒉𝒚′𝟐 = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓 + (𝟎. 𝟏)(𝟎. 𝟒𝟓𝟕𝟎𝟕𝟓) = −𝟎. 𝟖𝟏𝟏𝟑𝟔𝟕𝟓
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟑 = 𝒇(𝒙𝟑 , 𝒚
𝒚 ̅𝟑 ) = −𝟐𝒙𝟑 − 𝒚
̅𝟑 = −𝟐(𝟎. 𝟑) − (−𝟎. 𝟖𝟏𝟏𝟑𝟔𝟕𝟓) = 𝟎. 𝟐𝟏𝟏𝟑𝟔𝟕𝟓
𝒉 ′ 𝟎. 𝟏
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟑 = 𝒚𝟐 + ̅′𝟑 ] = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓 +
[𝒚𝟐 + 𝒚 [𝟎. 𝟒𝟓𝟕𝟎𝟕𝟓 + 𝟎. 𝟐𝟏𝟏𝟑𝟔𝟕𝟓]
𝟐 𝟐
= −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓
𝒚′𝟑 = −𝟐𝒙𝟑 − 𝒚𝟑 = −𝟐(𝟎. 𝟑) − (−𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓) = 𝟎. 𝟐𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓
𝒊 = 𝟒: 𝒙𝟒 = 𝟎. 𝟒
̅𝟒 = 𝒚𝟑 + 𝒉𝒚′𝟑 = −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓 + (𝟎. 𝟏)(𝟎. 𝟐𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓) = −𝟎. 𝟖𝟎𝟏𝟐𝟖𝟕𝟓𝟖𝟕𝟓
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟒 = 𝒇(𝒙𝟒 , 𝒚
𝒚 ̅𝟒 = −𝟐(𝟎. 𝟒) − (−𝟎. 𝟖𝟎𝟏𝟐𝟖𝟕𝟓𝟖𝟕𝟓) = 𝟏. 𝟐𝟖𝟕𝟓𝟖𝟕𝟓 × 𝟏𝟎−𝟑
̅𝟒 ) = −𝟐𝒙𝟒 − 𝒚
𝒉 ′
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟒 = 𝒚𝟑 + ̅′𝟒 ]
[𝒚 + 𝒚
𝟐 𝟑
𝟎. 𝟏
= −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓 + [𝟎. 𝟐𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓 + 𝟏. 𝟐𝟖𝟕𝟓𝟖𝟕𝟓 × 𝟏𝟎−𝟑 ]
𝟐
= −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖
𝒚′𝟒 = −𝟐𝒙𝟒 − 𝒚𝟒 = −𝟐(𝟎. 𝟒) − (−𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖) = 𝟎. 𝟎𝟏𝟐𝟒𝟎𝟓𝟖
𝒊 = 𝟓: 𝒙𝟓 = 𝟎. 𝟓
̅𝟓 = 𝒚𝟒 + 𝒉𝒚′𝟒 = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖 + (𝟎. 𝟏)(𝟎. 𝟎𝟏𝟐𝟒𝟎𝟓𝟖) = −𝟎. 𝟖𝟏𝟏𝟏𝟔𝟓𝟐𝟐
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟓 = 𝒇(𝒙𝟓 , 𝒚
𝒚 ̅𝟓 ) = −𝟐𝒙𝟓 − 𝒚
̅𝟓 = −𝟐(𝟎. 𝟓) − (−𝟎. 𝟖𝟏𝟏𝟏𝟔𝟓𝟐𝟐) = −𝟎. 𝟏𝟖𝟖𝟖𝟑𝟒𝟕𝟖
𝒉 ′ 𝟎. 𝟏
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟓 = 𝒚𝟒 + ̅′𝟓 ] = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖 +
[𝒚𝟒 + 𝒚 [𝟎. 𝟎𝟏𝟐𝟒𝟎𝟓𝟖 − 𝟎. 𝟏𝟖𝟖𝟖𝟑𝟒𝟕𝟖]
𝟐 𝟐
= −𝟎. 𝟖𝟐𝟏𝟐𝟐𝟕𝟐𝟒𝟗

Solution Summary & Comparison between Euler and Heun Methods


𝒙 𝒚𝒆𝒙𝒂𝒄𝒕 𝒚𝑬𝒖𝒍𝒆𝒓 % 𝑬𝒓𝒓𝒐𝒓 𝒚𝑯𝒆𝒖𝒏 % 𝑬𝒓𝒓𝒐𝒓
0 -1.00000 -1.00000 0 -1.00000 0
0.1 -0.91451 -0.90000 1.59 -0.91500 0.05
0.2 -0.85619 -0.83000 3.06 -0.857075 0.10
0.3 -0.82245 -0.78700 4.31 -0.823652875 0.15
0.4 -0.81096 -0.76830 5.26 -0.81240580 0.18
0.5 -0.81959 -0.77147 5.87 -0.821227249 0.20

Page 9 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

The Modified Euler Method


Also called: The Improved Polygon Method, or The Midpoint Method.
To numerically solve:
𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐
𝒅𝒙
Euler’s method: Slope is taken at the starting point 𝒙𝒊 of the interval, [𝒙𝒊 , 𝒙𝒊+𝟏 ].
Heun’s method: Slope is taken as the average value of the starting and end points
of the interval [𝒙𝒊 , 𝒙𝒊+𝟏 ].
Modified Euler Method:
The slope is taken at the midpoint of the interval [𝒙𝒊 , 𝒙𝒊+𝟏 ], i.e., at 𝒙𝒊+𝟏/𝟐
Steps:
1. Apply Euler’s method on half of the interval:
𝟏
𝒚𝒊+𝟏/𝟐 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) (𝟏)
𝟐
2. Calculate the slope at the midpoint:
𝒚′𝒊+𝟏/𝟐 = 𝒇(𝒙𝒊+𝟏/𝟐 , 𝒚𝒊+𝟏/𝟐 ) (𝟐)
3. Extrapolate from 𝒙𝒊 𝒕𝒐 𝒙𝒊+𝟏 using Euler’s formula:
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉 𝒇(𝒙
⏟ 𝒊+𝟏/𝟐 , 𝒚𝒊+𝟏/𝟐 ) (𝟑)
𝒔𝒍𝒐𝒑𝒆 𝒂𝒕 𝒙𝒊+𝟏/𝟐 ,𝒚𝒊+𝟏/𝟐

Substitute for 𝒙𝒊+𝟏/𝟐 , 𝒚𝒊+𝟏/𝟐 in (3)

𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + [𝒇(𝒙𝒊 + 𝒉/𝟐, 𝒚𝒊 + 𝒇(𝒙𝒊 , 𝒚𝒊 ) )] 𝒉 (𝟒)
𝟐

Page 10 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Graphical depiction of the midpoint method: (a) Eqn (1) and (b) Eqn (3).

Example:
Use the Midpoint method to numerically integrate
𝒅𝒚
= 𝒚′ = −𝟐𝒙 − 𝒚 = 𝒇(𝒙, 𝒚), 𝒚(𝟎) = −𝟏
𝒅𝒙

from 𝒙 = 𝟎 to 𝒙 = 𝟎. 𝟓 with a step size of 𝒉 = 𝟎. 𝟏


Solution
𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊

Page 11 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒊 = 𝟎: 𝒙𝒐 = 𝟎,
𝒚𝒐 = 𝒚(𝟎) = −𝟏, 𝒚′𝒐 = 𝒚′ (𝟎) = −𝟐(𝟎) − 𝒚(𝟎) = 𝟎 − (−𝟏) = 𝟏
𝒊 = 𝟏: 𝒙𝟏 = 𝟎. 𝟏,
Intermediate point (between 𝒊 = 𝟎, 𝒊 = 𝟏):
𝟏 𝟏 𝟏
𝒚𝟏/𝟐 = 𝒚𝟎 + 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 ) = 𝒚𝟎 + 𝒉𝒚′ (𝒙𝒐 ) = 𝒚𝟎 + 𝒉(−𝟐𝒙𝒐 − 𝒚𝒐 )
𝟐 𝟐 𝟐
𝒚𝟏/𝟐 = −𝟏 + 𝟎. 𝟓(𝟎. 𝟏)(−𝟐(𝟎) − (−𝟏)) = −𝟏 + 𝟎. 𝟎𝟓 = −𝟎. 𝟗𝟓
𝒚′𝟏/𝟐 = 𝒇(𝒙𝟏/𝟐 , 𝒚𝟏/𝟐 ) = −𝟐(𝟎. 𝟎𝟓) − (−𝟎. 𝟗𝟓) = 𝟎. 𝟖𝟓

𝒚𝟏 = 𝒚𝟎 + 𝒉𝒇(𝒙𝟏/𝟐 , 𝒚𝟏/𝟐 ) = −𝟏 + (𝟎. 𝟏)(𝟎. 𝟖𝟓) = −𝟎. 𝟗𝟏𝟓


𝒊 = 𝟐: 𝒙𝟏 = 𝟎. 𝟐,
Intermediate point (between 𝒊 = 𝟏, 𝒊 = 𝟐):
𝟏 𝟏 𝟏
𝒚𝟑/𝟐 = 𝒚𝟏 + 𝒉𝒇(𝒙𝟏 , 𝒚𝟏 ) = 𝒚𝟏 + 𝒉𝒚′ (𝒙𝟏 ) = 𝒚𝟏 + 𝒉(−𝟐𝒙𝟏 − 𝒚𝟏 )
𝟐 𝟐 𝟐
𝒚𝟑/𝟐 = −𝟎. 𝟗𝟏𝟓 + 𝟎. 𝟓(𝟎. 𝟏)(−𝟐(𝟎. 𝟏) − (−𝟎. 𝟗𝟏𝟓)) = −𝟎. 𝟖𝟕𝟗𝟐𝟓
𝒚′𝟑/𝟐 = 𝒇(𝒙𝟑/𝟐 , 𝒚𝟑/𝟐 ) = −𝟐(𝟎. 𝟏𝟓) − (−𝟎. 𝟖𝟕𝟗𝟐𝟓) = 𝟎. 𝟓𝟕𝟗𝟐𝟓

𝒚𝟐 = 𝒚𝟏 + 𝒉𝒇(𝒙𝟑/𝟐 , 𝒚𝟑/𝟐 ) = −𝟎. 𝟗𝟏𝟓 + (𝟎. 𝟏)(𝟎. 𝟓𝟕𝟗𝟐𝟓) = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓


𝒊 = 𝟑: 𝒙𝟑 = 𝟎. 𝟑,
Intermediate point (between 𝒊 = 𝟐, 𝒊 = 𝟑):
𝟏 𝟏 𝟏
𝒚𝟓/𝟐 = 𝒚𝟐 + 𝒉𝒇(𝒙𝟐 , 𝒚𝟐 ) = 𝒚𝟐 + 𝒉𝒚′ (𝒙𝟐 ) = 𝒚𝟐 + 𝒉(−𝟐𝒙𝟐 − 𝒚𝟐 )
𝟐 𝟐 𝟐
𝒚𝟓/𝟐 = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓 + 𝟎. 𝟓(𝟎. 𝟏)(−𝟐(𝟎. 𝟐) − (−𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓)) = −𝟎. 𝟖𝟑𝟒𝟐𝟐𝟏𝟐𝟓
𝒚′𝟓/𝟐 = 𝒇(𝒙𝟓/𝟐 , 𝒚𝟓/𝟐 ) = −𝟐(𝟎. 𝟐𝟓) − (−𝟎. 𝟖𝟑𝟒𝟐𝟐𝟏𝟐𝟓) = 𝟎. 𝟑𝟑𝟒𝟐𝟐𝟏𝟐𝟓

𝒚𝟑 = 𝒚𝟐 + 𝒉𝒇(𝒙𝟓/𝟐 , 𝒚𝟓/𝟐 ) = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓 + (𝟎. 𝟏)(𝟎. 𝟑𝟑𝟒𝟐𝟐𝟏𝟐𝟓 ) = −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟖


𝒊 = 𝟒: 𝒙𝟒 = 𝟎. 𝟒,
Intermediate point (between 𝒊 = 𝟑, 𝒊 = 𝟒):
𝟏 𝟏 𝟏
𝒚𝟕/𝟐 = 𝒚𝟑 + 𝒉𝒇(𝒙𝟑 , 𝒚𝟑 ) = 𝒚𝟑 + 𝒉𝒚′ (𝒙𝟑 ) = 𝒚𝟑 + 𝒉(−𝟐𝒙𝟑 − 𝒚𝟑 )
𝟐 𝟐 𝟐
𝒚𝟕/𝟐 = −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟖 + 𝟎. 𝟓(𝟎. 𝟏)(−𝟐(𝟎. 𝟑) − (−𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟖)) = −𝟎. 𝟖𝟏𝟐𝟒𝟕𝟎𝟐𝟑
𝒚′𝟕/𝟐 = 𝒇(𝒙𝟓/𝟐 , 𝒚𝟓/𝟐 ) = −𝟐(𝟎. 𝟑𝟓) − (−𝟎. 𝟖𝟏𝟐𝟒𝟕𝟎𝟐𝟑 ) = 𝟎. 𝟏𝟏𝟐𝟒𝟕𝟎𝟐𝟑

𝒚𝟒 = 𝒚𝟑 + 𝒉𝒇(𝒙𝟕/𝟐 , 𝒚𝟕/𝟐 ) = −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟖 + (𝟎. 𝟏)(𝟎. 𝟏𝟏𝟐𝟒𝟕𝟎𝟐𝟑 ) = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖𝟓


𝒊 = 𝟓: 𝒙𝟒 = 𝟎. 𝟓,
Page 12 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Intermediate point (between 𝒊 = 𝟒, 𝒊 = 𝟓):


𝟏 𝟏 𝟏
𝒚𝟗/𝟐 = 𝒚𝟒 + 𝒉𝒇(𝒙𝟒 , 𝒚𝟒 ) = 𝒚𝟒 + 𝒉𝒚′ (𝒙𝟒 ) = 𝒚𝟒 + 𝒉(−𝟐𝒙𝟒 − 𝒚𝟒 )
𝟐 𝟐 𝟐
𝒚𝟗/𝟐 = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖𝟓 + 𝟎. 𝟓(𝟎. 𝟏)(−𝟐(𝟎. 𝟒) − (−𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖𝟓)) = −𝟎. 𝟖𝟏𝟏𝟕𝟖𝟓𝟓𝟔
𝒚′𝟗/𝟐 = 𝒇(𝒙𝟗/𝟐 , 𝒚𝟗/𝟐 ) = −𝟐(𝟎. 𝟒𝟓) − (−𝟎. 𝟖𝟏𝟏𝟕𝟖𝟓𝟓𝟔 ) = −𝟎. 𝟎𝟖𝟖𝟐𝟏𝟒𝟒𝟒

𝒚𝟓 = 𝒚𝟒 + 𝒉𝒇(𝒙𝟗/𝟐 , 𝒚𝟗/𝟐 ) = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖𝟓 + (𝟎. 𝟏)(−𝟎. 𝟎𝟖𝟖𝟐𝟏𝟒𝟒𝟒 ) = −𝟎. 𝟖𝟐𝟏𝟐𝟐𝟕𝟑

Page 13 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Runge – Kutta Methods


Numerical solution of:
𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐 (𝟏)
𝒅𝒙
1. Euler’s Method
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 = 𝒚𝒊 + 𝒇(𝒙𝒊 , 𝒚𝒊 ). 𝒉 (𝟐)
2. Heun’s Method
𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + [ 𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ))] 𝒉 (𝟑)
𝟐 𝟐
3. Midpoint Method
𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒇 (𝒙𝒊 + 𝒉/𝟐, 𝒚𝒊 + 𝒇(𝒙𝒊 , 𝒚𝒊 )) . 𝒉 (𝟒)
𝟐

General Form – nth order Runge-Kutta method


𝒚𝒊+𝟏 = 𝒚𝒊 + 𝝓(𝒙𝒊 , 𝒚𝒊 , 𝒉). 𝒉 (𝟓)
𝝓 = 𝒂𝟏 𝒌𝟏 + 𝒂𝟐 𝒌𝟐 + 𝒂𝟑 𝒌𝟑 + ⋯ + 𝒂𝒏 𝒌𝒏 (𝟔)
Where 𝒂𝟏 , 𝒂𝟐 , … , 𝒂𝒏 are constants, and 𝒌𝟏 , 𝒌𝟐 , … , 𝒌𝒏 are given as:
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 ) (𝟕)
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒌𝟏 𝒉) (𝟖)
𝒌𝟑 = 𝒇(𝒙𝒊 + 𝒑𝟐 𝒉, 𝒚𝒊 + 𝒒𝟐𝟏 𝒌𝟏 𝒉 + 𝒒𝟐𝟐 𝒌𝟐 𝒉) (𝟗)
𝒌𝟒 = 𝒇(𝒙𝒊 + 𝒑𝟑 𝒉, 𝒚𝒊 + 𝒒𝟑𝟏 𝒌𝟏 𝒉 + 𝒒𝟑𝟐 𝒌𝟐 𝒉 + 𝒒𝟑𝟑 𝒌𝟑 𝒉) (𝟏𝟎)
...


𝒌𝒏 = 𝒇(𝒙𝒊 + 𝒑𝒏−𝟏 𝒉, 𝒚𝒊 + 𝒒𝒏−𝟏,𝟏 𝒌𝟏 𝒉 + 𝒒𝒏−𝟏,𝟐 𝒌𝟐 𝒉 + ⋯ + 𝒒𝒏−𝟏,𝒏−𝟏 𝒌𝒏−𝟏 𝒉) (𝟏𝟏)

For 𝒏 = 𝟏: From (6) & (7):


𝝓 = 𝒂𝟏 𝒌𝟏 = 𝒂𝟏 𝒇(𝒙𝒊 , 𝒚𝒊 ) (𝟏𝟐)
Substitute (12) in (5):
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒂𝟏 𝒇(𝒙𝒊 , 𝒚𝒊 ). 𝒉 (𝟏𝟑)

Page 14 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Compare (13) with (2):  Euler’s Method


𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 = 𝒚𝒊 + 𝒇(𝒙𝒊 , 𝒚𝒊 ). 𝒉 (𝟐)
𝒂𝟏 = 𝟏
Euler’s Method  1st order R-K

For 𝒏 = 𝟐: From (6) & (8):


𝝓 = 𝒂𝟏 𝒌𝟏 + 𝒂𝟐 𝒌𝟐 (𝟏𝟒)
𝝓 = 𝒂𝟏 𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )) (𝟏𝟓)
Substitute (15) in (5):
𝒚𝒊+𝟏 = 𝒚𝒊 + [𝒂𝟏 𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ))]. 𝒉 (𝟏𝟔)
Compare (16) with (3):  Heun’s Method:
𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + [ 𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ))] 𝒉 (𝟑)
𝟐 𝟐
𝟏 𝟏
𝒂𝟏 = , 𝒂 𝟐 = , 𝒑𝟏 = 𝟏, 𝒒𝟏𝟏 = 𝟏
𝟐 𝟐

Heun’s Method  2nd order R-K


𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒌𝟏 𝒉 + 𝒌𝟐 𝒉
𝟐 𝟐
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)
Compare (16) with (4):  Modified Euler’s Method:
𝒉 𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒇 (𝒙𝒊 + , 𝒚𝒊 + 𝒇(𝒙𝒊 , 𝒚𝒊 )) . 𝒉 (𝟒)
𝟐 𝟐

𝒂𝟏 = 𝟎, 𝒂𝟐 = 𝟏, 𝒑𝟏 = 𝟏/𝟐, 𝒒𝟏𝟏 = 𝟏/𝟐


Modified Euler’s Method  2nd order R-K
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒌𝟐 𝒉
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏 𝟏
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟐 𝟐

Page 15 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Derivation of the 2nd Order Runge-Kutta Methods


Numerical solution of:
𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐 (𝟏)
𝒅𝒙
2nd order R-K: Solution to (1):
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒂𝟏 𝒌𝟏 + 𝒂𝟐 𝒌𝟐 )𝒉 (𝟐)
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒌𝟏 𝒉)

→ 𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒂𝟏 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒉𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒌𝟏 𝒉) (𝟑)

𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒌𝟏 𝒉) ≡ 𝒇(𝒙𝒊 + ∆𝒙, 𝒚𝒊 + ∆𝒚)


Taylor series to expand 𝒇(𝒙𝒊 + ∆𝒙, 𝒚𝒊 + ∆𝒚) ≡ 𝒇(𝒙𝒊 + 𝒑𝟏 𝒉, 𝒚𝒊 + 𝒒𝟏𝟏 𝒌𝟏 𝒉):
∆𝒙 ≡ 𝒑𝟏 𝒉, ∆𝒚 ≡ 𝒒𝟏𝟏 𝒌𝟏 𝒉
𝟏
𝒇(𝒙 + ∆𝒙, 𝒚 + ∆𝒚) = 𝒇(𝒙, 𝒚) + ∆𝒙𝒇𝒙 + ∆𝒚𝒇𝒚 + [∆𝒙𝟐 𝒇𝒙𝒙 + 𝟐∆𝒙∆𝒚𝒇𝒙𝒚 + ∆𝒚𝟐 𝒇𝒚𝒚 ] + ⋯
𝟐!
Where,
𝝏𝒇 𝝏𝒇 𝝏𝟐 𝒇 𝝏𝟐 𝒇 𝝏𝟐 𝒇
𝒇𝒙 = , 𝒇𝒚 = , 𝒇𝒙𝒙 = 𝟐, 𝒇𝒚𝒚 = 𝟐 , 𝒇𝒙𝒚 =
𝝏𝒙 𝝏𝒚 𝝏𝒙 𝝏𝒚 𝝏𝒙𝝏𝒚

𝟏 𝟏
𝒇(𝒙 + ∆𝒙, 𝒚 + ∆𝒚) = 𝒇(𝒙, 𝒚) + ∆𝒙𝒇𝒙 + ∆𝒚𝒇𝒚 + ∆𝒙𝟐 𝒇𝒙𝒙 + ∆𝒙∆𝒚𝒇𝒙𝒚 + ∆𝒚𝟐 𝒇𝒚𝒚 + ⋯
𝟐 𝟐

For 𝑶(𝒉𝟐 ) 𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏:


𝒇(𝒙 + ∆𝒙, 𝒚 + ∆𝒚) = 𝒇(𝒙, 𝒚) + ∆𝒙𝒇𝒙 + ∆𝒚𝒇𝒚 + ⋯ (𝟒)

Substitute (4) in (3):


2nd order R-K:

𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒂𝟏 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒉 [𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒑𝟏 𝒉𝒇𝒙 + 𝒒𝟏𝟏 𝒌𝟏 𝒉𝒇𝒚 ]

𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒂𝟏 + 𝒂𝟐 )𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒑𝟏 𝒉𝟐 𝒇𝒙 + 𝒂𝟐 𝒉𝟐 𝒒𝟏𝟏 𝒌𝟏 𝒇𝒚 (𝟓)

Taylor series expansion for 𝒚(𝒙):


𝒉𝟐 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 + 𝒚𝒊 + 𝑶(𝒉𝟑 )
𝟐!
𝒘𝒉𝒆𝒓𝒆, 𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊 , 𝒚′𝒊 = 𝒇(𝒙𝒊 , 𝒚𝒊 ), 𝒚′′ ′
𝒊 = 𝒇 (𝒙𝒊 , 𝒚𝒊 )

Page 16 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒉𝟐 ′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇 (𝒙𝒊 , 𝒚𝒊 ) + +𝑶(𝒉𝟑 ) (𝟔)
𝟐!
𝒅𝒇 𝝏𝒇 𝝏𝒇 𝒅𝒚 𝝏𝒇 𝝏𝒇
𝒇′ (𝒙, 𝒚) = = + = +𝒇 (𝟕)
𝒅𝒙 𝝏𝒙 𝝏𝒚 𝒅𝒙 𝝏𝒙 𝝏𝒚
Substitute (7) in (6):
𝒉𝟐 𝒉𝟐
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇𝒙 + 𝒇𝒇𝒚 (𝟖)
𝟐 𝟐
Compare Taylor series expansion (8) with the 2nd order R-K scheme (5):
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒂𝟏 + 𝒂𝟐 )𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒑𝟏 𝒉𝟐 𝒇𝒙 + 𝒂𝟐 𝒉𝟐 𝒒𝟏𝟏 𝒌𝟏 𝒇𝒚 (𝟓)

Equating coefficients of 𝒇, 𝒇𝒙 , 𝒇𝒚 in (8) and (5):


𝑪𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕 𝒐𝒇 𝒇: 𝒂𝟏 + 𝒂𝟐 = 𝟏
𝑪𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕 𝒐𝒇 𝒇𝒙 : 𝒂𝟐 𝒑𝟏 = 𝟏/𝟐
𝑪𝒐𝒆𝒇𝒇𝒊𝒄𝒊𝒆𝒏𝒕 𝒐𝒇 𝒇𝒙 : 𝒂𝟐 𝒒𝟏𝟏 = 𝟏/𝟐
 3 Equations & 4 unknowns (𝒂𝟏 , 𝒂𝟐 , 𝒑𝟏 , 𝒒𝟏𝟏 )
 Assume one and solve for the remaining 3 unknowns:

Heun’s Method:
𝒂𝟐 = 𝟏/𝟐, → 𝒂𝟏 = 𝟏/𝟐, 𝒑𝟏 = 𝟏, 𝒒𝟏𝟏 = 𝟏
𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + ( 𝒌𝟏 + 𝒌𝟐 ) 𝒉
𝟐 𝟐
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
Modified Euler (Improved Polygon)
𝒂𝟐 = 𝟏, → 𝒂𝟏 = 𝟎, 𝒑𝟏 = 𝟏, 𝒒𝟏𝟏 = 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒌𝟐 𝒉
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉/𝟐, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟐
Ralston’s Method
𝒂𝟐 = 𝟐/𝟑, → 𝒂𝟏 = 𝟏/𝟑, 𝒑𝟏 = 𝟑/𝟒, 𝒒𝟏𝟏 = 𝟑/𝟒
𝟏 𝟐
𝒚𝒊+𝟏 = 𝒚𝒊 + ( 𝒌𝟏 + 𝒌𝟐 ) 𝒉
𝟑 𝟑
Page 17 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟑 𝟑
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟒 𝟒
3rd Order R-K Method:
𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒌 + 𝟒𝒌𝟐 + 𝒌𝟑 )
𝟔 𝟏
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏 𝟏
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟐 𝟐
𝒌𝟑 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 − 𝒉𝒌𝟏 + 𝟐𝒉𝒌𝟐 )
4th Order R-K Method:
𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒌 + 𝟐𝒌𝟐 + 𝟐𝒌𝟑 + 𝒌𝟒 )
𝟔 𝟏
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏 𝟏
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟐 𝟐
𝟏 𝟏
𝒌𝟑 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟐 )
𝟐 𝟐
𝒌𝟒 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟑 )
5th Order R-K Method:
𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝟕𝒌𝟏 + 𝟑𝟐𝒌𝟑 + 𝟐𝒌𝟑 + 𝟏𝟐𝒌𝟒 + 𝟑𝟐𝒌𝟓 + 𝟕𝒌𝟔 )
𝟗𝟎
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏 𝟏
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟒 𝟒
𝟏 𝟏 𝟏
𝒌𝟑 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 + 𝒉𝒌𝟐 )
𝟒 𝟖 𝟖
𝟏 𝟏
𝒌𝟒 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 − 𝒉𝒌𝟐 + 𝒉𝒌𝟑 )
𝟐 𝟐
𝟑 𝟑 𝟗
𝒌𝟓 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 + 𝒉𝒌 )
𝟒 𝟏𝟔 𝟏𝟔 𝟒
𝟑 𝟐 𝟏𝟐 𝟏𝟐 𝟖
𝒌𝟔 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 − 𝒉𝒌𝟏 + 𝒉𝒌𝟐 + 𝒉𝒌𝟑 − 𝒉𝒌𝟒 + 𝒉𝒌𝟓 )
𝟕 𝟕 𝟕 𝟕 𝟕

Page 18 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Higher Order ODE’s


To use R-K methods, a higher order ODE can be reduced to a system of 1st order
ODE’s:
mth Order ODE:
𝒅𝒎 𝒚
𝒎
= 𝒚(𝒎) = 𝒇(𝒙, 𝒚, 𝒚′ , … , 𝒚(𝒎−𝟏) )
𝒅𝒙
(𝒎−𝟏)
𝒚(𝒙𝒐 ) = 𝒚𝒐 , 𝒚′ (𝒙𝒐 ) = 𝒚′𝒐 , 𝒚′′ (𝒙𝒐 ) = 𝒚′′
𝒐, …, 𝒚(𝒎−𝟏) (𝒙𝒐 ) = 𝒚𝒐

Reduce above system to m 1st order ODE’s:


𝒚𝟏 = 𝒚, → 𝒚′𝟏 = 𝒚′ = 𝒚𝟐 , 𝒚𝟏 (𝒙𝒐 ) = 𝒚𝒐
𝒚 𝟐 = 𝒚′ , → 𝒚′𝟐 = 𝒚′′ = 𝒚𝟑 , 𝒚𝟐 (𝒙𝒐 ) = 𝒚′𝒐
𝒚𝟑 = 𝒚′′ , → 𝒚′𝟑 = 𝒚′′′ = 𝒚𝟒 , 𝒚𝟑 (𝒙𝒐 ) = 𝒚′′
𝒐


(𝒎−𝟏)
𝒚𝒎 = 𝒚(𝒎−𝟏) , → 𝒚′𝒎 = 𝒚(𝒎) = 𝒇(𝒙, 𝒚, 𝒚′ , … , 𝒚(𝒎−𝟏) ), 𝒚𝒎 (𝒙𝒐 ) = 𝒚𝒐

Example 1
Reduce the 3rd order ODE given below to a system of 1st order ODE’s.
𝒚′′′ = 𝒇(𝒙, 𝒚, 𝒚′ , 𝒚′′ )
𝒚(𝟎) = 𝒚𝒐 , 𝒚′ (𝟎) = 𝒚′𝒐 , 𝒚′′ (𝟎) = 𝒚′′
𝒐

𝒚𝟏 = 𝒚
𝒚𝟐 = 𝒚′
𝒚𝟑 = 𝒚′′
→ 𝒚′𝟏 = 𝒚𝟐 , 𝒚𝟏 (𝟎) = 𝒚(𝟎) = 𝒚𝒐
→ 𝒚′𝟐 = 𝒚𝟑 , 𝒚𝟐 (𝟎) = 𝒚′ (𝟎) = 𝒚′𝒐
→ 𝒚′𝟑 = 𝒇(𝒙, 𝒚, 𝒚′ , 𝒚′′ ), 𝒚𝟑 (𝟎) = 𝒚′′ (𝟎) = 𝒚′′
𝒐

Example 2 (Exercise)
Reduce the 3rd order ODE given below to a system of 1st order ODEs.
𝒚′′′ + 𝒚 𝒚′′ = 𝟎, 𝒚(𝟎) = 𝟎, 𝒚′ (𝟎) = 𝟎, 𝒚′ (𝟖) = 𝟎

Page 19 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Systems of Equations
 Many practical problems in engineering and science require the simultaneous
solution of a system of ordinary differential equations rather than a single
equation.

A typical system of ODEs:


𝒚′𝟏 = 𝒇𝟏 (𝒙, 𝒚𝟏 , 𝒚𝟐 , … , 𝒚𝒏 ), 𝒚𝟏 (𝒙𝒐 ) = 𝒚𝟏,𝒐
𝒚′𝟐 = 𝒇𝟐 (𝒙, 𝒚𝟏 , 𝒚𝟐 , … , 𝒚𝒏 ) 𝒚𝟐 (𝒙𝒐 ) = 𝒚𝟐,𝒐
𝒚′𝟑 = 𝒇𝟑 (𝒙, 𝒚𝟏 , 𝒚𝟐 , … , 𝒚𝒏 ) 𝒚𝟑 (𝒙𝒐 ) = 𝒚𝟑,𝒐
… … ..
𝒚′𝒏 = 𝒇𝒏 (𝒙, 𝒚𝟏 , 𝒚𝟐 , … , 𝒚𝒏 ) 𝒚𝒏 (𝒙𝒐 ) = 𝒚𝒏,𝒐
 All the methods discussed previously for single equations can be extended to
the system shown above.
 The procedure for solving a system of equations simply involves applying the
one-step technique for every equation at each step before proceeding to the
next step.

Euler’s Method:

For a single ODE:

𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )

For a system of ODEs:


𝒚𝟏,𝒊+𝟏 = 𝒚𝟏,𝒊 + 𝒉𝒇𝟏 (𝒙𝒊 , 𝒚𝒊 )

𝒚𝟐,𝒊+𝟏 = 𝒚𝟐,𝒊 + 𝒉𝒇𝟐 (𝒙𝒊 , 𝒚𝒊 )

𝒚𝟑,𝒊+𝟏 = 𝒚𝟑,𝒊 + 𝒉𝒇𝟑 (𝒙𝒊 , 𝒚𝒊 )


………
𝒚𝒏,𝒊+𝟏 = 𝒚𝒏,𝒊 + 𝒉𝒇𝒏 (𝒙𝒊 , 𝒚𝒊 )

Heun’s Method:
For a single ODE:
𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + ( 𝒌𝟏 + 𝒌𝟐 ) 𝒉, 𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 ), 𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟐 𝟐
For a system of ODEs:

Page 20 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝟏 𝟏
𝒚𝟏,𝒊+𝟏 = 𝒚𝟏,𝒊 + ( 𝒌𝟏,𝟏 + 𝒌𝟐,𝟏 ) 𝒉, 𝒌𝟏,𝟏 = 𝒇𝟏 (𝒙𝒊 , 𝒚𝒊 ), 𝒌𝟐,𝟏 = 𝒇𝟐 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏,𝟏 )
𝟐 𝟐
𝟏 𝟏
𝒚𝟐,𝒊+𝟏 = 𝒚𝟐,𝒊 + ( 𝒌𝟏,𝟐 + 𝒌𝟐,𝟐 ) 𝒉, 𝒌𝟏,𝟐 = 𝒇𝟐 (𝒙𝒊 , 𝒚𝒊 ), 𝒌𝟐,𝟐 = 𝒇𝟐 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏,𝟐 )
𝟐 𝟐
……
……
𝟏 𝟏
𝒚𝒏,𝒊+𝟏 = 𝒚𝒏,𝒊 + ( 𝒌𝟏,𝒏 + 𝒌𝟐,𝒏 ) 𝒉, 𝒌𝟏,𝒏 = 𝒇𝒏 (𝒙𝒊 , 𝒚𝒊 ), 𝒌𝟐,𝒏 = 𝒇𝒏 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒉𝒌𝟏,𝒏 )
𝟐 𝟐
Example
Integrate the following set of ODEs numerically from 𝒙 = 𝟎 𝒕𝒐 𝒙 = 𝟐 with a step
size of 0.5 using the modified Euler’s method.
𝒅𝒚𝟏
= −𝟎. 𝟓𝒚𝟏 = 𝒇𝟏 (𝒙, 𝒚𝟏 ), 𝒚𝟏 (𝟎) = 𝟒
𝒅𝒙

𝒅𝒚𝟐
= 𝟒 − 𝟎. 𝟑𝒚𝟐 − 𝟎. 𝟏𝒚𝟏 = 𝒇𝟐 (𝒙, 𝒚𝟏 , 𝒚𝟐 ), 𝒚𝟐 (𝟎) = 𝟔
𝒅𝒙

Solution
The modified Euler’s method for 1 equation:
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒌𝟐 𝒉
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉/𝟐, 𝒚𝒊 + 𝒉𝒌𝟏 )
𝟐
The modified Euler’s method for a system of equations:
Equation 1:
𝒚𝟏,𝒊+𝟏 = 𝒚𝟏,𝒊 + 𝒌𝟐,𝟏 𝒉
𝒌𝟏,𝟏 = 𝒇𝟏 (𝒙𝒊 , 𝒚𝒊 )
𝒉 𝟏 𝟏
𝒌𝟐,𝟏 = 𝒇𝟏 (𝒙𝒊 + , 𝒚𝟏,𝒊 + 𝒉𝒌𝟏,𝟏 , 𝒚𝟐,𝒊 + 𝒉𝒌𝟏,𝟐 )
𝟐 𝟐 𝟐
Equation 2:
𝒚𝟐,𝒊+𝟏 = 𝒚𝟐,𝒊 + 𝒌𝟐,𝟐 𝒉
𝒌𝟏,𝟐 = 𝒇𝟐 (𝒙𝒊 , 𝒚𝒊 )
𝒉 𝟏 𝟏
𝒌𝟐,𝟐 = 𝒇𝟐 (𝒙𝒊 + , 𝒚𝟏,𝒊 + 𝒉𝒌𝟏,𝟏 , 𝒚𝟐,𝒊 + 𝒉𝒌𝟏,𝟐 )
𝟐 𝟐 𝟐

Page 21 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Step 1 (from 0 to 0.5):

Equation 1
𝒚𝟏,𝒊+𝟏 = 𝒚𝟏,𝒊 + 𝒌𝟐,𝟏 𝒉
𝒌𝟏,𝟏 = 𝒇𝟏 (𝒙𝒊 , 𝒚𝒊 ) = −𝟎. 𝟓𝒚𝟏 (𝟎) = −𝟎. 𝟓(𝟒) = −𝟐

𝒉 𝟏 𝟏 𝟎. 𝟓
𝒌𝟐,𝟏 = 𝒇𝟏 (𝒙𝒊 + , 𝒚𝟏,𝒊 + 𝒉𝒌𝟏,𝟏 , 𝒚𝟐,𝒊 + 𝒉𝒌𝟏,𝟐 ) = 𝒇𝟏 (𝟎 + 𝟎. 𝟐𝟓, 𝟒 + (−𝟐))
𝟐 𝟐 𝟐 𝟐

= 𝒇𝟏 (𝟎. 𝟐𝟓, 𝟑. 𝟓) = −𝟎. 𝟓𝒚𝟏 (𝟎. 𝟐𝟓) = −𝟎. 𝟓(𝟑. 𝟓) = −𝟏. 𝟕𝟓


𝒚𝟏,𝒊+𝟏 = 𝒚𝟏,𝒊 + 𝒌𝟐,𝟏 𝒉 = 𝟒 + (−𝟏. 𝟕𝟓)(𝟎. 𝟓) = 𝟑. 𝟏𝟐𝟓 = 𝒚𝟏 (𝟎. 𝟓)
Equation 2
𝒚𝟐,𝒊+𝟏 = 𝒚𝟐,𝒊 + 𝒌𝟐,𝟐 𝒉
𝒌𝟏,𝟐 = 𝒇𝟐 (𝒙𝒊 , 𝒚𝒊 ) = 𝟒 − 𝟎. 𝟑𝒚𝟐 (𝒙𝒊 ) − 𝟎. 𝟏𝒚𝟏 (𝒙𝒊 ) = 𝟒 − 𝟎. 𝟑𝒚𝟐 (𝟎) − 𝟎. 𝟏𝒚𝟏 (𝒙𝒊 )
= 𝟒 − 𝟎. 𝟑(𝟔) − 𝟎. 𝟏(𝟒) = 𝟏. 𝟖
𝒉 𝟏 𝟏
𝒌𝟐,𝟐 = 𝒇𝟐 (𝒙𝒊 + , 𝒚𝟏,𝒊 + 𝒉𝒌𝟏,𝟏 , 𝒚𝟐,𝒊 + 𝒉𝒌𝟏,𝟐 )
𝟐 𝟐 𝟐
𝟎. 𝟓 𝟎. 𝟓 𝟎. 𝟓
= 𝒇𝟐 (𝟎 + ,𝟒+ (−𝟐), 𝟔 + (𝟏. 𝟖)) = 𝒇𝟐 (𝟎. 𝟐𝟓, 𝟑. 𝟓, 𝟔. 𝟒𝟓)
𝟐 𝟐 𝟐
= 𝟒 − 𝟎. 𝟑𝒚𝟐 (𝟎. 𝟐𝟓) − 𝟎. 𝟏𝒚𝟏 (𝟎. 𝟐𝟓) = 𝟒 − 𝟎. 𝟑(𝟔. 𝟒𝟓) − 𝟎. 𝟏(𝟑. 𝟓)
= 𝟏. 𝟕𝟏𝟓
𝒚𝟐,𝒊+𝟏 = 𝒚𝟐,𝒊 + 𝒌𝟐,𝟐 𝒉 = 𝟔 + 𝟏. 𝟕𝟏𝟓(𝟎. 𝟓) = 𝟔. 𝟖𝟓𝟕𝟖 = 𝒚𝟐 (𝟎. 𝟓)
Step 2 (from 0.5 to 1.0):

Exercise: Repeat the same procedure as in step 1, and continue calculations to


step 4.

Page 22 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Adaptive Step Size Control

 Fixed step size is good when the solution changes gradually.


 When the solution experiences steep change in some interval  very small
step size is required in that interval in order to capture the steep change.
 One method to solve such a problem is to use very fine step size all over the
domain. This has the disadvantage of performing more computations
unnecessarily in regions where the solution changes gradually.

 Another method to capture abrupt changes properly is to use small step sizes
in the region of abrupt changes and large steps in regions with gradual change,
i.e., a step size that “adapts” to the solution. This is called adaptive step size
control.
 To use “Adaptive Step Size Control”: The local truncation error has to be
obtained at each step. This error estimate is then used to decide on increasing
or decreasing the step size.

Page 23 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Two Methods for Estimating the Local Error:


1. Estimate the error as the difference between two solutions using the same
order R-K scheme but with different step sizes

newExplanation:
1. Use 4th order R-K method:
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒂𝟏 𝒌𝟏 + 𝒂𝟐 𝒌𝟐 + 𝒂𝟑 𝒌𝟑 + 𝒂𝟒 𝒌𝟒 )𝒉
𝒘𝒊𝒕𝒉 𝒉𝟏 = ∆𝒙 = 𝒙𝒊+𝟏 − 𝒙𝒊 → 𝒈𝒆𝒕 𝒚𝟏 = 𝒚𝟏 (𝒙𝒊+𝟏 )

2. Use the same 4th order R-K method, but with 𝒉𝟐 = ∆𝒙/𝟐.
→ 𝒈𝒆𝒕 𝒚𝟐 = 𝒚𝟐 (𝒙𝒊+𝟏 ) (more accurate)

3. Define error as: ∆= 𝒚𝟐 − 𝒚𝟏


4. Given specific accuracy level as ∆𝒎
5. Press et. al. criterion:
∆ 𝜶 𝟎. 𝟐𝟎, 𝚫 < 𝚫𝒎 𝒉𝒏𝒆𝒘 > 𝒉
𝒉𝒏𝒆𝒘 = 𝒉 | 𝒎 | , 𝜶={ , ( )
∆ 𝟎. 𝟐𝟓, 𝚫 > 𝚫𝒎 𝒉𝒏𝒆𝒘 < 𝒉
Go to step 1.
2. Estimate the error as the difference between two solutions using different
order R-K methods. For example: use 4th and 5th order R-K methods, and
error is the difference between the two solutions  modify the step size
accordingly. This involves much computations: Using 4th and 5th order R-K
involve 4+5 = 9 function evaluations. To overcome this problem, Use:
The Runge-Kutta Fehlberg Method
Use the 5th order R-K method together with the 4th order R-K method, where
the 5th order R-K employs the function evaluations from the 4th order method:

Page 24 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

4th order R-K:


𝟐𝟓 𝟏𝟒𝟎𝟖 𝟐𝟏𝟗𝟕 𝟏
̂𝒊+𝟏 = 𝒚𝒊 + [
𝒚 𝒌𝟏 + 𝒌𝟑 + 𝒌𝟒 − 𝒌 𝟓 ] 𝒉 (𝟏)
𝟐𝟏𝟔 𝟐𝟓𝟔𝟓 𝟒𝟏𝟎𝟒 𝟓
5th order R-K:
𝟏𝟔 𝟔𝟔𝟓𝟔 𝟐𝟖𝟓𝟔𝟏 𝟗 𝟐
𝒚𝒊+𝟏 = 𝒚𝒊 + [ 𝒌𝟏 + 𝒌𝟑 + 𝒌𝟒 − 𝒌𝟓 + 𝒌 ]𝒉 (𝟐)
𝟏𝟑𝟓 𝟏𝟐𝟖𝟐𝟓 𝟓𝟔𝟒𝟑𝟎 𝟓𝟎 𝟓𝟓 𝟔
𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒉 𝒉
𝒌𝟐 = 𝒇(𝒙𝒊 + , 𝒚𝒊 + 𝒌 𝟏 )
𝟒 𝟒
𝟑𝒉 𝟑𝒉 𝟗𝒉
𝒌𝟑 = 𝒇(𝒙𝒊 + , 𝒚𝒊 + 𝒌𝟏 + 𝒌 )
𝟖 𝟑𝟐 𝟑𝟐 𝟐
𝟏𝟐𝒉 𝟏𝟗𝟑𝟐𝒉 𝟕𝟐𝟎𝟎𝒉 𝟕𝟐𝟗𝟔𝒉
𝒌𝟒 = 𝒇(𝒙𝒊 + , 𝒚𝒊 + 𝒌𝟏 − 𝒌𝟐 + 𝒌 )
𝟏𝟑 𝟐𝟏𝟗𝟕 𝟐𝟏𝟗𝟕 𝟐𝟏𝟗𝟕 𝟑
𝟒𝟑𝟗𝒉 𝟑𝟔𝟖𝟎𝒉 𝟖𝟒𝟓𝒉
𝒌𝟓 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 − 𝟖𝒉𝒌𝟐 + 𝒌𝟑 − 𝒌 )
𝟐𝟏𝟔 𝟓𝟏𝟑 𝟒𝟏𝟎𝟒 𝟒
𝒉 𝟖𝒉 𝟑𝟓𝟒𝟒𝒉 𝟏𝟖𝟓𝟗𝒉 𝟏𝟏𝒉
𝒌𝟔 = 𝒇(𝒙𝒊 + , 𝒚𝒊 − 𝒌𝟏 + 𝟐𝒉𝒌𝟐 − 𝒌𝟑 + 𝒌𝟒 − 𝒌 )
𝟐 𝟐𝟕 𝟐𝟓𝟔𝟓 𝟒𝟏𝟎𝟒 𝟒𝟎 𝟓

̂𝒊+𝟏 = ∆
𝑬𝒓𝒓𝒐𝒓 = 𝑬𝒒. 𝟐 − 𝑬𝒒. 𝟏 = 𝒚𝒊+𝟏 − 𝒚
𝟏 𝟏𝟐𝟖 𝟐𝟏𝟗𝟕 𝟏 𝟐
∆= [ 𝒌𝟏 − 𝒌𝟑 − 𝒌𝟒 + 𝒌𝟓 + 𝒌 ]𝒉
𝟑𝟔𝟎 𝟒𝟐𝟕𝟓 𝟕𝟓𝟐𝟒𝟎 𝟓𝟎 𝟓𝟓 𝟔

̂𝒊+𝟏 + ∆
𝑺𝒐𝒍𝒖𝒕𝒊𝒐𝒏: 𝒚𝒊+𝟏 = 𝒚

New Step Size:

𝑻𝑶𝑳.𝒉 𝟏/𝟒
𝒉𝒏𝒆𝒘 = 𝒉 [ ]
𝟐|∆|

Page 25 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Multistep Methods
Numerical solution of:
𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐
𝒅𝒙
Methods studied so far: Given 𝒚𝒊  find 𝒚𝒊+𝟏  Solution at current step uses
information at the previous step only.
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉. 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒚𝒊+𝟐 = 𝒚𝒊+𝟏 + 𝒉. 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 )
𝒚𝒊+𝟑 = 𝒚𝒊+𝟐 + 𝒉. 𝒇(𝒙𝒊+𝟐 , 𝒚𝒊+𝟐 )
…..
Once solution is found at 𝒙𝒊+𝟏 , 𝒙𝒊+𝟐 , 𝒙𝒊+𝟑 , … why not using more information from
previous steps instead of using just one info. at the previous step?
 Multistep Methods:
𝒅𝒚
= 𝒇(𝒙, 𝒚)
𝒅𝒙
𝒚𝒊+𝟏 𝒙𝒊+𝟏

∫ 𝒅𝒚 = ∫ 𝒇(𝒙, 𝒚)𝒅𝒙
𝒚𝒊 𝒙𝒊

Using the Trapezoidal rule to evaluate the R.H.S of the above equation:
𝒉
𝒚𝒊+𝟏 − 𝒚𝒊 = [𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 )]
𝟐
𝒘𝒉𝒆𝒓𝒆 𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊

Adams – Bashforth Formula:


Write the Taylor series for y at 𝒙𝒊 :
𝒉𝟐 ′ 𝒉𝟑 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒇𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯
𝟐 𝟔
𝒉 ′ 𝒉𝟐 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉 [𝒇𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ ]
𝟐 𝟔
Backward Difference for 𝒇′𝒊 :

Page 26 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒇𝒊 − 𝒇𝒊−𝟏 𝟏 ′′
𝒇′𝒊 = + 𝒉𝒇𝒊 + 𝑶(𝒉𝟐 )
𝒉 𝟐
𝑺𝒖𝒃𝒔𝒕𝒊𝒕𝒖𝒕𝒆 𝒇𝒐𝒓 𝒇′𝒊
𝒉 𝒇𝒊 − 𝒇𝒊−𝟏 𝟏 ′′ 𝒉𝟐 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉 [𝒇𝒊 + { + 𝒉𝒇𝒊 } + 𝒇𝒊 ] + ⋯
𝟐 𝒉 𝟐 𝟔
𝟑 𝟏 𝟓 𝟑 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉 [ 𝒇𝒊 − 𝒇𝒊−𝟏 ] + 𝒉 𝒇𝒊 + ⋯
⏟ 𝟐 𝟐 𝟏𝟐
𝟐𝒏𝒅 𝒐𝒓𝒅𝒆𝒓 𝑨𝒅𝒂𝒎𝒔−𝑩𝒂𝒔𝒉𝒇𝒐𝒓𝒕𝒉 𝒇𝒐𝒓𝒎𝒖𝒍𝒂

Higher order 𝑨𝒅𝒂𝒎𝒔 − 𝑩𝒂𝒔𝒉𝒇𝒐𝒓𝒕𝒉 𝒇𝒐𝒓𝒎𝒖𝒍𝒂𝒔  Use finite difference


formulas for 𝒇′′ ′′′
𝒊 , 𝒇𝒊 , ….

Example: Backward difference for 𝒇′′


𝒊 that can be used in the above equation

to obtain a higher order Adams-Bashforth formula:


𝒇𝒊 − 𝟐𝒇𝒊−𝟏 + 𝒇𝒊−𝟐
𝒇′′
𝒊 = ,
𝒉𝟐

Page 27 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

HW Problem Set 8 (ODEs)

Page 28 of 28

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy