Unit 9 (Ordinary Differential Equations)
Unit 9 (Ordinary Differential Equations)
Unit-9
(Ordinary Differential Equations)
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Contents (Unit-9):
1) Euler’s Method (Sec 25.1)
Derivatives
𝑑𝑑𝑑𝑑(𝑡𝑡)
− 𝑣𝑣(𝑡𝑡) = 𝑒𝑒 𝑡𝑡
𝑑𝑑𝑑𝑑 𝑥𝑥(𝑡𝑡): Unknown Function
𝑑𝑑 2 𝑥𝑥(𝑡𝑡) 𝑑𝑑𝑑𝑑(𝑡𝑡)
−5 + 2𝑥𝑥(𝑡𝑡) = cos( 𝑡𝑡)
𝑑𝑑𝑡𝑡 2 𝑑𝑑𝑑𝑑
(Independent Variable)
the variable with respect to which
other variables are differentiated
𝑑𝑑𝑑𝑑(𝑡𝑡)
− 𝑥𝑥(𝑡𝑡) = 𝑒𝑒 𝑡𝑡 1st order ODE
𝑑𝑑𝑑𝑑
𝑑𝑑 2 𝑥𝑥(𝑡𝑡) 𝑑𝑑𝑑𝑑 𝑡𝑡
−5 + 2𝑥𝑥(𝑡𝑡) = cos( 𝑡𝑡) 2nd order ODE
𝑑𝑑𝑡𝑡 2 𝑑𝑑𝑑𝑑
3
𝑑𝑑 2 𝑥𝑥(𝑡𝑡) 𝑑𝑑𝑑𝑑(𝑡𝑡)
− + 2𝑥𝑥 4 (𝑡𝑡) = 1 2nd order ODE
𝑑𝑑𝑡𝑡 2 𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑(𝑡𝑡) 𝑑𝑑𝑑𝑑(𝑡𝑡)
− 𝑥𝑥(𝑡𝑡) = 𝑒𝑒 𝑡𝑡 Linear ODE − cos( 𝑥𝑥(𝑡𝑡)) = 1 Non-Linear ODE
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
2
𝑑𝑑 𝑥𝑥(𝑡𝑡)
3
𝑑𝑑𝑑𝑑(𝑡𝑡) 𝑑𝑑 2 𝑥𝑥(𝑡𝑡) 𝑑𝑑𝑑𝑑(𝑡𝑡)
− + 𝑥𝑥(𝑡𝑡) = 1 Non-Linear ODE − + 𝑥𝑥(𝑡𝑡) = 1 Non-Linear ODE
𝑑𝑑𝑡𝑡 2 𝑑𝑑𝑑𝑑 𝑑𝑑𝑡𝑡 2 𝑑𝑑𝑑𝑑
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Ordinary Differential Equations:
A solution to a differential equation is a function that satisfies the original equation.
𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸: 𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆𝑆:
𝑑𝑑𝑑𝑑(𝑡𝑡)
= −𝑒𝑒 −𝑡𝑡
𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑(𝑡𝑡)
+ 𝑥𝑥(𝑡𝑡) = −𝑒𝑒 −𝑡𝑡 + 𝑒𝑒 −𝑡𝑡 = 0
Is it Unique? 𝑑𝑑𝑑𝑑
All functions of the form 𝑥𝑥 𝑡𝑡 = 𝑘𝑘𝑒𝑒 −𝑡𝑡 (where 𝑘𝑘 is a real constant) are solutions
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Ordinary Differential Equations:
Uniqueness of a solution
In order to uniquely specify a solution to an 𝑛𝑛𝑡𝑡𝑡 order differential equation we need 𝑛𝑛 conditions
𝑑𝑑 2 𝑦𝑦(𝑥𝑥)
2
+ 4𝑦𝑦(𝑥𝑥) = 0 2nd order ODE
𝑑𝑑𝑡𝑡
More Difficult
Initial Conditions Boundary Conditions
Initial Value Boundary Value
All conditions are at one point of the The conditions are not at one point
Problems Problems
independent variable of the independent variable
𝑥𝑥(0) = 1, 𝑥𝑥(0)
̇ = 2.5 𝑥𝑥(0) = 1, 𝑥𝑥(2)
̇ = 1.5
Same Different
Linearity
Linear ODE
Non-Linear ODE
Auxiliary Conditions
Initial Value Problems
Boundary Value Problems
x0 x1 x2 x
h h
2nd Step
True Solution
Which is exactly the same error that was incurred in the initial step of previous example
𝑓𝑓(𝑥𝑥, 𝑦𝑦) = 1 + 𝑥𝑥 2
𝑦𝑦3 = 𝑦𝑦2 + 𝑓𝑓 𝑥𝑥2 , 𝑦𝑦2 ℎ = −3.9598 + 0.01 1 + 1.02 2 = −3.9394 2 1.02 −3.9595 −3.95959
3 1.03 −3.9394 −3.93091
Midpoint Method
These methods provide the accuracy of the 2nd order Taylor series method without the need to calculate 2nd order derivative
Runge-Kutta Methods
This method provide the accuracy of the high order Taylor series method without the need to calculate high order derivative
Predictor
the determination of two derivatives for the interval, one
at the initial point and another at the end point
Corrector
obtain an improved estimate
Predictor
slopes.
One at the initial point (𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 ) and another one at the
0
predicted value of the final point (𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1 )
Corrector
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Improvements of Euler’s Method:
Heun’s Method
0
𝑓𝑓(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 ) + 𝑓𝑓(𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1 )
𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 =
2 0
𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 𝑓𝑓(𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1 )
0
(𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1 )
1
(𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1 )
(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 )
𝑥𝑥0 𝑥𝑥𝑖𝑖+1
Analytical Solution
Predictor
Slope at (1,5)
Notice: The errors sometimes grow as the iterations proceed, such increases can occur, especially for large step sizes.
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Improvements of Euler’s Method (Example):
1 & 15
Iteration/step
Step-1
Predictor: 𝑦𝑦10 = 𝑦𝑦0 + ℎ𝑓𝑓(𝑥𝑥0 , 𝑦𝑦0 ) = 1 + 0.1(2) = 1.2
ℎ
Corrector: 𝑦𝑦11 = 𝑦𝑦0 + 𝑓𝑓(𝑥𝑥0 , 𝑦𝑦0 ) + 𝑓𝑓(𝑥𝑥1 , 𝑦𝑦10 ) = 1.2105
2
Step-2
ℎ
Corrector: 𝑦𝑦21 = 𝑦𝑦1 + 𝑓𝑓(𝑥𝑥1 , 𝑦𝑦1 ) + 𝑓𝑓(𝑥𝑥2 , 𝑦𝑦20 ) = 1.4452
2
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Improvements of Euler’s Method:
Midpoint Method
This technique uses Euler’s method to predict a value of 𝑦𝑦 at
the midpoint of the interval
(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 )
𝑥𝑥0 𝑥𝑥 1 𝑥𝑥𝑖𝑖+1
𝑖𝑖+
2
Step-1 ℎ
𝑦𝑦 1 = 𝑦𝑦0 + 𝑓𝑓(𝑥𝑥0 , 𝑦𝑦0 ) = 1 + 0.05(1 + 0 + 1) = 1.1
0+
2 2
Step-2 ℎ
𝑦𝑦 1 = 𝑦𝑦1 + 𝑓𝑓(𝑥𝑥1 , 𝑦𝑦1 ) = 1.2103 + .05(1 + 0.01 + 1.2103) = 1.3213
1+
2 2
Euler Method
𝑂𝑂(ℎ2 ) 𝑂𝑂(ℎ)
𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + ℎ𝑓𝑓(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 )
Heun′s Method
0
Predictor: 𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + ℎ𝑓𝑓(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 )𝑂𝑂(ℎ3 )𝑂𝑂(ℎ2 )
𝑂𝑂(ℎ3 ) 𝑂𝑂(ℎ2 )
𝑘𝑘+1 ℎ 𝑘𝑘
Corrector: 𝑦𝑦𝑖𝑖+1 = 𝑦𝑦𝑖𝑖 + 𝑓𝑓(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 ) + 𝑓𝑓(𝑥𝑥𝑖𝑖+1 , 𝑦𝑦𝑖𝑖+1 )
2
Midpoint
ℎ
𝑦𝑦 1 = 𝑦𝑦𝑖𝑖 + 𝑓𝑓(𝑥𝑥𝑖𝑖 , 𝑦𝑦𝑖𝑖 )𝑂𝑂(ℎ3 )𝑂𝑂(ℎ2 )
𝑖𝑖+
2 2 𝑂𝑂(ℎ3 ) 𝑂𝑂(ℎ2 )
Heun’s Method with a Single Corrector The Midpoint Method Ralston’s Method
(𝑎𝑎2 = 1⁄2) (𝑎𝑎2 = 1) (𝑎𝑎2 = 2⁄3)
Notice:
The answer is exact, because the true solution is quartic, thus the 4th order method gives exact result.
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Runge-Kutta Methods (Example):
Use classical 4th order RK method to integrate the given systems.
a) Step size ℎ = 0.5 with 𝑦𝑦 0 = 1
b) Step size ℎ = 0.5 with 𝑦𝑦 0 = 2 from 𝑥𝑥 = 0 to 𝑥𝑥 = 0.5.
Notice:
More Difficult
Initial Conditions Boundary Conditions
Initial Value Boundary Value
All conditions are at one point of the The conditions are not at one point
Problems Problems
independent variable of the independent variable
𝑥𝑥(0) = 1, 𝑥𝑥(0)
̇ = 2.5 𝑥𝑥(0) = 1, 𝑥𝑥(2)
̇ = 1.5
Same Different
Finite-Difference Method
Check if the boundary conditions is satisfied otherwise modify the guess and resolve the problem
Target
Target
Target
Thus, a linear differential equation is transformed into a set of simultaneous algebraic equations that
can be solved.