E7 2021 Lecture24
E7 2021 Lecture24
Lecture 24
Numerical Methods for Ordinary Differential Equations (ODE)
Fall 2021
Instructor: Shaofan Li
The Initial Conditions ---- The Initial-Value Problem (IVP)
A differential equation of order n has a solution containing n arbitrary constant,
which is called the general solution of the ODE.
If we assume that rotations are small, we can use the small-angle approximation
Consider the first order ODE defined on an interval with a given boundary (or initial) condition:
𝑑𝑦
= 𝑓(𝑡, 𝑦) 𝑡 ∈ [𝑡0 , 𝑡𝑛 ] 𝑦(𝑡 = 𝑡0 ) = 𝑦0
𝑑𝑡
We can divide the interval into equal lengths of h (step-size) to obtain the numerical grid:
[𝑡0 , 𝑡1 , 𝑡2 , … , 𝑡𝑛−1 , 𝑡𝑛 ] where 𝑡0 < 𝑡1 < 𝑡2 , … , 𝑡𝑓−1 < 𝑡𝑛 and 𝑡𝑖+1 = 𝑡𝑖 + ℎ 𝑓𝑜𝑟 𝑖 = 1,2, … , 𝑛
Starting with the initial value 𝑦0 , we can predict the next function value by making use of
the slope at 𝑡0 to extrapolate linearly over the step size h
𝑦1 = 𝑦0 + ℎ ∙ 𝑓 𝑡0 , 𝑦0
Euler’s Method
𝑦1 = 𝑦0 + ℎ ∙ 𝑓 𝑡0 , 𝑦0
𝑦1 = 𝑦0 + ℎ ∙ 𝑓 𝑡0 , 𝑦0
𝑦2 = 𝑦1 + ℎ ∙ 𝑓 𝑡1 , 𝑦1
𝑦3 = 𝑦2 + ℎ ∙ 𝑓 𝑡2 , 𝑦2
𝑦𝑖+1 = 𝑦𝑖 + ℎ ∙ 𝑓 𝑡𝑖 , 𝑦𝑖
𝑦2 𝑦3 𝑦4
The algorithm is ‘explicit’ since it only requires information at
𝑦1
the previous time step 𝑡𝑖 to compute the state at 𝑡𝑖+1
𝑡
Implicit Euler Method
𝑡 ∈ [𝑡0 , 𝑡𝑛 ] 𝑦(𝑡 = 𝑡0 ) = 𝑦0
𝑑𝑦
= 𝑓(𝑡, 𝑦)
𝑑𝑡
Another method can be derived using the 1st order Taylor expansion around 𝑡𝑖+1 and evaluating it at 𝑡𝑖
𝑦 0 =1 𝑥 ∈ [0,4]
Euler’s method converges to the analytical solution as step size gets smaller.
(II): Runge-Kutta Method
Second-Order Runge-Kutta (RK2) Method Midpoint rule
We use midpoint rule to integrate this equation: 𝑑𝑦
= 𝑓(𝑡, 𝑦)
𝑑𝑡
Central Difference
Fourth-Order Runge-Kutta (RK4) Method
It is possible to get higher accuracy methods by evaluating the derivative several times at
different locations (in contrast to Euler’s method, where we evaluate the derivative at the
current step only).
RK4 Method: ℎ
𝑦𝑖+1 = 𝑦𝑖 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
where
𝑘1 = 𝑓(𝑡𝑖 , 𝑦𝑖 )
𝑘2 = 𝑓(𝑡𝑖 + ℎ/2 , 𝑦𝑖 + ℎ/2 𝑘1 )
𝑘3 = 𝑓(𝑡𝑖 + ℎ/2 , 𝑦𝑖 + ℎ/2 𝑘2 )
𝑘4 = 𝑓(𝑡𝑖 + ℎ , 𝑦𝑖 + ℎ 𝑘3 )
The Explanation of Fourth-Order Runge-Kutta (RK4) Method
ℎ
𝑦𝑖+1 = 𝑦𝑖 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6
𝑘1 = 𝑓(𝑡𝑖 , 𝑦𝑖 )
𝑘2 = 𝑓(𝑡𝑖 + ℎ/2 , 𝑦𝑖 + ℎ/2 𝑘1 )
𝑘3 = 𝑓(𝑡𝑖 + ℎ/2 , 𝑦𝑖 + ℎ/2 𝑘2 )
𝑘4 = 𝑓(𝑡𝑖 + ℎ , 𝑦𝑖 + ℎ 𝑘3 )
𝑘1 = 𝑓(𝑡𝑖 , 𝑦𝑖 )
ℎ 𝑘2 = 𝑓(𝑡𝑖 + ℎ/2 , 𝑦𝑖 + ℎ/2 𝑘1 )
𝑦𝑖+1 = 𝑦𝑖 + (𝑘1 + 2𝑘2 + 2𝑘3 + 𝑘4 )
6 𝑘3 = 𝑓(𝑡𝑖 + ℎ/2 , 𝑦𝑖 + ℎ/2 𝑘2 )
𝑘4 = 𝑓(𝑡𝑖 + ℎ , 𝑦𝑖 + ℎ 𝑘3 )
Fourth-Order Runge-Kutta (RK4) Method
𝑦′ = 𝑦 − 𝑡2 + 1 𝑦 0 = 0.5
0≤𝑡≤2 ∆𝑡 = 0.5
Example:
𝑦1ሶ = 𝑦2 𝑦1 0 = 𝜃0
𝑔
𝑦2ሶ = − 𝑦1 𝑦2 0 = 𝜃ሶ0
𝐿
Reduction of order
𝑑𝑌 0 1 𝜃0
= 𝑌 𝑌(0) = ሶ
𝑑𝑡 −𝑔/𝐿 0 𝜃0
1
Consider the problem in the interval t = [0,10] with given initial conditions 𝑌(0) =
1
Single Pendulum Problem
Order of Accuracy and Stability of Numerical Integration
Accuracy: How fast a scheme gets close to the exact solution, as a function of step size.
Stability: Ability of a scheme to keep the error from growing, as it integrates forward.
Conditionally Stable = Stability of the scheme depends on the choice of the step size
Unconditionally Stable = Scheme is stable no matter the step size
Why we are interested in Implicit Euler Method ?
𝑡 ∈ [𝑡0 , 𝑡𝑛 ] 𝑦(𝑡 = 𝑡0 ) = 𝑦0
𝑑𝑦
= 𝑓(𝑡, 𝑦)
𝑑𝑡
Another method can be derived using the 1st order Taylor expansion around 𝑡𝑖+1 and evaluating it at 𝑡𝑖
Explicit and implicit schemes are unstable for this choice of the step size.
Which line shows the behavior of the error for
Euler’s method?
A
1 C E=Ch^1
B Log E= logC + 1 * logh
1
2
1 3
1
D
E) None of these
Euler’s method
A) Forward Euler;
B) Backward Euler;
C) Midpoint method
D) Simpson’s method
E) I’m not sure
Consider this 2nd order Runge-Kuttaformula
Calculate k1=f(xi,yi)
Then
yi+1= yi + k2h -> predict yi+1 using midpoint slope over h
yi+1= yi + f(xi+0.5h, yi+0.5k1h) h
yi+1= yi + f(xi+1/2, y*i+1/2) h -> Midpoint rule
Happy Thanksgiving