Ordinary Differential Equations
Ordinary Differential Equations
Page 1 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒉𝟐 ′′ 𝒉𝟑 ′′′ 𝒉𝟒 (𝟒)
𝒚(𝒙) = 𝒚(𝒙𝒐 ) + 𝒉𝒚′ (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + 𝒚 (𝒙𝒐 ) + ⋯
𝟐 𝟑! 𝟒!
Example
Use the Taylor series method to numerically integrate
𝒅𝒚
= −𝟐𝒙 − 𝒚, 𝒚(𝟎) = −𝟏
𝒅𝒙
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.
𝒅𝒚
= 𝒇(𝒙, 𝒚), 𝒚(𝒙𝒐 ) = 𝒚𝒐
𝒅𝒙
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
Euler Scheme
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒚′𝒊 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )
Euler’s method.
Example:
Use Euler’s method to numerically integrate
𝒅𝒚
= −𝟐𝒙 − 𝒚 = 𝒇(𝒙, 𝒚), 𝒚(𝟎) = −𝟏
𝒅𝒙
Page 4 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
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
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
𝒅𝒚
= −𝟐𝒙 − 𝒚 = 𝒇(𝒙, 𝒚), 𝒚(𝟎) = −𝟏
𝒅𝒙
Page 8 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒊 = 𝟑: 𝒙𝟑 = 𝟎. 𝟑
̅𝟑 = 𝒚𝟐 + 𝒉𝒚′𝟐 = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓 + (𝟎. 𝟏)(𝟎. 𝟒𝟓𝟕𝟎𝟕𝟓) = −𝟎. 𝟖𝟏𝟏𝟑𝟔𝟕𝟓
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟑 = 𝒇(𝒙𝟑 , 𝒚
𝒚 ̅𝟑 ) = −𝟐𝒙𝟑 − 𝒚
̅𝟑 = −𝟐(𝟎. 𝟑) − (−𝟎. 𝟖𝟏𝟏𝟑𝟔𝟕𝟓) = 𝟎. 𝟐𝟏𝟏𝟑𝟔𝟕𝟓
𝒉 ′ 𝟎. 𝟏
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟑 = 𝒚𝟐 + ̅′𝟑 ] = −𝟎. 𝟖𝟓𝟕𝟎𝟕𝟓 +
[𝒚𝟐 + 𝒚 [𝟎. 𝟒𝟓𝟕𝟎𝟕𝟓 + 𝟎. 𝟐𝟏𝟏𝟑𝟔𝟕𝟓]
𝟐 𝟐
= −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓
𝒚′𝟑 = −𝟐𝒙𝟑 − 𝒚𝟑 = −𝟐(𝟎. 𝟑) − (−𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓) = 𝟎. 𝟐𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓
𝒊 = 𝟒: 𝒙𝟒 = 𝟎. 𝟒
̅𝟒 = 𝒚𝟑 + 𝒉𝒚′𝟑 = −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓 + (𝟎. 𝟏)(𝟎. 𝟐𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓) = −𝟎. 𝟖𝟎𝟏𝟐𝟖𝟕𝟓𝟖𝟕𝟓
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟒 = 𝒇(𝒙𝟒 , 𝒚
𝒚 ̅𝟒 = −𝟐(𝟎. 𝟒) − (−𝟎. 𝟖𝟎𝟏𝟐𝟖𝟕𝟓𝟖𝟕𝟓) = 𝟏. 𝟐𝟖𝟕𝟓𝟖𝟕𝟓 × 𝟏𝟎−𝟑
̅𝟒 ) = −𝟐𝒙𝟒 − 𝒚
𝒉 ′
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟒 = 𝒚𝟑 + ̅′𝟒 ]
[𝒚 + 𝒚
𝟐 𝟑
𝟎. 𝟏
= −𝟎. 𝟖𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓 + [𝟎. 𝟐𝟐𝟑𝟔𝟓𝟐𝟖𝟕𝟓 + 𝟏. 𝟐𝟖𝟕𝟓𝟖𝟕𝟓 × 𝟏𝟎−𝟑 ]
𝟐
= −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖
𝒚′𝟒 = −𝟐𝒙𝟒 − 𝒚𝟒 = −𝟐(𝟎. 𝟒) − (−𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖) = 𝟎. 𝟎𝟏𝟐𝟒𝟎𝟓𝟖
𝒊 = 𝟓: 𝒙𝟓 = 𝟎. 𝟓
̅𝟓 = 𝒚𝟒 + 𝒉𝒚′𝟒 = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖 + (𝟎. 𝟏)(𝟎. 𝟎𝟏𝟐𝟒𝟎𝟓𝟖) = −𝟎. 𝟖𝟏𝟏𝟏𝟔𝟓𝟐𝟐
𝑷𝒓𝒆𝒅𝒊𝒄𝒕𝒐𝒓: 𝒚
̅′𝟓 = 𝒇(𝒙𝟓 , 𝒚
𝒚 ̅𝟓 ) = −𝟐𝒙𝟓 − 𝒚
̅𝟓 = −𝟐(𝟎. 𝟓) − (−𝟎. 𝟖𝟏𝟏𝟏𝟔𝟓𝟐𝟐) = −𝟎. 𝟏𝟖𝟖𝟖𝟑𝟒𝟕𝟖
𝒉 ′ 𝟎. 𝟏
𝑪𝒐𝒓𝒓𝒆𝒄𝒕𝒐𝒓: 𝒚𝟓 = 𝒚𝟒 + ̅′𝟓 ] = −𝟎. 𝟖𝟏𝟐𝟒𝟎𝟓𝟖 +
[𝒚𝟒 + 𝒚 [𝟎. 𝟎𝟏𝟐𝟒𝟎𝟓𝟖 − 𝟎. 𝟏𝟖𝟖𝟖𝟑𝟒𝟕𝟖]
𝟐 𝟐
= −𝟎. 𝟖𝟐𝟏𝟐𝟐𝟕𝟐𝟒𝟗
Page 9 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒉
𝒚𝒊+𝟏 = 𝒚𝒊 + [𝒇(𝒙𝒊 + 𝒉/𝟐, 𝒚𝒊 + 𝒇(𝒙𝒊 , 𝒚𝒊 ) )] 𝒉 (𝟒)
𝟐
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
𝒅𝒚
= 𝒚′ = −𝟐𝒙 − 𝒚 = 𝒇(𝒙, 𝒚), 𝒚(𝟎) = −𝟏
𝒅𝒙
Page 11 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
Page 14 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
Page 15 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝟏 𝟏
𝒇(𝒙 + ∆𝒙, 𝒚 + ∆𝒚) = 𝒇(𝒙, 𝒚) + ∆𝒙𝒇𝒙 + ∆𝒚𝒇𝒚 + ∆𝒙𝟐 𝒇𝒙𝒙 + ∆𝒙∆𝒚𝒇𝒙𝒚 + ∆𝒚𝟐 𝒇𝒚𝒚 + ⋯
𝟐 𝟐
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):
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒂𝟏 + 𝒂𝟐 )𝒉𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒂𝟐 𝒑𝟏 𝒉𝟐 𝒇𝒙 + 𝒂𝟐 𝒉𝟐 𝒒𝟏𝟏 𝒌𝟏 𝒇𝒚 (𝟓)
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
…
(𝒎−𝟏)
𝒚𝒎 = 𝒚(𝒎−𝟏) , → 𝒚′𝒎 = 𝒚(𝒎) = 𝒇(𝒙, 𝒚, 𝒚′ , … , 𝒚(𝒎−𝟏) ), 𝒚𝒎 (𝒙𝒐 ) = 𝒚𝒐
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.
Euler’s Method:
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉𝒇(𝒙𝒊 , 𝒚𝒊 )
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
Equation 1
𝒚𝟏,𝒊+𝟏 = 𝒚𝟏,𝒊 + 𝒌𝟐,𝟏 𝒉
𝒌𝟏,𝟏 = 𝒇𝟏 (𝒙𝒊 , 𝒚𝒊 ) = −𝟎. 𝟓𝒚𝟏 (𝟎) = −𝟎. 𝟓(𝟒) = −𝟐
𝒉 𝟏 𝟏 𝟎. 𝟓
𝒌𝟐,𝟏 = 𝒇𝟏 (𝒙𝒊 + , 𝒚𝟏,𝒊 + 𝒉𝒌𝟏,𝟏 , 𝒚𝟐,𝒊 + 𝒉𝒌𝟏,𝟐 ) = 𝒇𝟏 (𝟎 + 𝟎. 𝟐𝟓, 𝟒 + (−𝟐))
𝟐 𝟐 𝟐 𝟐
Page 22 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
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
newExplanation:
1. Use 4th order R-K method:
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒂𝟏 𝒌𝟏 + 𝒂𝟐 𝒌𝟐 + 𝒂𝟑 𝒌𝟑 + 𝒂𝟒 𝒌𝟒 )𝒉
𝒘𝒊𝒕𝒉 𝒉𝟏 = ∆𝒙 = 𝒙𝒊+𝟏 − 𝒙𝒊 → 𝒈𝒆𝒕 𝒚𝟏 = 𝒚𝟏 (𝒙𝒊+𝟏 )
2. Use the same 4th order R-K method, but with 𝒉𝟐 = ∆𝒙/𝟐.
→ 𝒈𝒆𝒕 𝒚𝟐 = 𝒚𝟐 (𝒙𝒊+𝟏 ) (more accurate)
Page 24 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
̂𝒊+𝟏 = ∆
𝑬𝒓𝒓𝒐𝒓 = 𝑬𝒒. 𝟐 − 𝑬𝒒. 𝟏 = 𝒚𝒊+𝟏 − 𝒚
𝟏 𝟏𝟐𝟖 𝟐𝟏𝟗𝟕 𝟏 𝟐
∆= [ 𝒌𝟏 − 𝒌𝟑 − 𝒌𝟒 + 𝒌𝟓 + 𝒌 ]𝒉
𝟑𝟔𝟎 𝟒𝟐𝟕𝟓 𝟕𝟓𝟐𝟒𝟎 𝟓𝟎 𝟓𝟓 𝟔
̂𝒊+𝟏 + ∆
𝑺𝒐𝒍𝒖𝒕𝒊𝒐𝒏: 𝒚𝒊+𝟏 = 𝒚
𝑻𝑶𝑳.𝒉 𝟏/𝟒
𝒉𝒏𝒆𝒘 = 𝒉 [ ]
𝟐|∆|
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:
𝒉
𝒚𝒊+𝟏 − 𝒚𝒊 = [𝒇(𝒙𝒊 , 𝒚𝒊 ) + 𝒇(𝒙𝒊+𝟏 , 𝒚𝒊+𝟏 )]
𝟐
𝒘𝒉𝒆𝒓𝒆 𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊
Page 26 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒇𝒊 − 𝒇𝒊−𝟏 𝟏 ′′
𝒇′𝒊 = + 𝒉𝒇𝒊 + 𝑶(𝒉𝟐 )
𝒉 𝟐
𝑺𝒖𝒃𝒔𝒕𝒊𝒕𝒖𝒕𝒆 𝒇𝒐𝒓 𝒇′𝒊
𝒉 𝒇𝒊 − 𝒇𝒊−𝟏 𝟏 ′′ 𝒉𝟐 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉 [𝒇𝒊 + { + 𝒉𝒇𝒊 } + 𝒇𝒊 ] + ⋯
𝟐 𝒉 𝟐 𝟔
𝟑 𝟏 𝟓 𝟑 ′′
𝒚𝒊+𝟏 = 𝒚𝒊 + 𝒉 [ 𝒇𝒊 − 𝒇𝒊−𝟏 ] + 𝒉 𝒇𝒊 + ⋯
⏟ 𝟐 𝟐 𝟏𝟐
𝟐𝒏𝒅 𝒐𝒓𝒅𝒆𝒓 𝑨𝒅𝒂𝒎𝒔−𝑩𝒂𝒔𝒉𝒇𝒐𝒓𝒕𝒉 𝒇𝒐𝒓𝒎𝒖𝒍𝒂
Page 27 of 28
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
Page 28 of 28