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

4-ODE- RK Methods

The document discusses advanced numerical methods for solving ordinary differential equations (ODEs), focusing on applications in engineering and science. It covers the classification of ODEs, including order, linearity, and homogeneity, and introduces numerical methods such as Euler's method and Heun's method for solving first-order ODEs. Examples are provided to illustrate the application of these methods, along with a programming task to implement the solutions in Matlab.

Uploaded by

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

4-ODE- RK Methods

The document discusses advanced numerical methods for solving ordinary differential equations (ODEs), focusing on applications in engineering and science. It covers the classification of ODEs, including order, linearity, and homogeneity, and introduces numerical methods such as Euler's method and Heun's method for solving first-order ODEs. Examples are provided to illustrate the application of these methods, along with a programming task to implement the solutions in Matlab.

Uploaded by

ali282h
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

MEIE6004: Advanced Numerical Methods

Ordinary Differential Equations


Runge Kutta Methods

Nasser A. Al‐Azri
Introduction
Modeling finds widespread application in science and engineering, serving to elucidate
system performance and natural occurrences. Employing mathematical representations,
typically in the form of differential equations, offers a cost-effective alternative to
experimental investigations. Several common modeling practices in engineering include:
Machine Dynamics: Utilizing differential
equations to depict mechanical system behavior,
with Newton's second law often formulated as a
second-order differential equation.
Control Systems: Employing differential
equations to depict and analyze control system
behavior, particularly in the design of controllers
to regulate dynamic systems.
Introduction
Thermo‐Fluids and Heat Transfer: 𝑇 𝑇
Employing differential equations to model 𝑄 𝑘𝐴
𝐿
heat transfer, fluid flow, turbulence, and the
Navier-Stokes equation, which characterizes
the movement of viscous flows.
Process Engineering: Utilizing differential
equations to model chemical reactions, mass
transfer, and transport phenomena in
chemical processes, critical for designing
reactors and separators.
Introduction
Example of Ordinary differential equations:

𝑑𝑦 Exponential growth equation where 𝑘 is the


𝑘𝑦
𝑑𝑡 growth rate.
Newton’s law of cooling where ℎ is the heat
𝑑𝑇
ℎ 𝑇 𝑇 𝑡 transfer coefficient and 𝑇 is the ambient
𝑑𝑡
temperature.
Mechanical vibration where 𝑚 is the mass, 𝑐 is
𝑑 𝑥 𝑑𝑥 the damping coefficient, 𝑘 is the spring constant
𝑚 𝑐 𝑘𝑥 𝑓 𝑡 and 𝑓 𝑡 is the external force applied to the
𝑑𝑡 𝑑𝑡
system.
Ordinary Differential Equations
An Ordinary Differential Equation (ODE) involves one independent variable taking
the standard form:

𝑑 𝑦 𝑑 𝑦 𝑑𝑦
𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 ⋯ 𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑦 ℎ 𝑥, 𝑦
𝑑𝑥 𝑑𝑥 𝑑𝑥
Analytical and numerical methods for solving ODEs are often valid for a limited
range of equations which makes understanding the classifications of ordinary
differential equations very important before using a solution method.
An ordinary differential equation can further be classified based on the following:
Ordinary Differential Equations
1. Order: the order of a differential equation is the highest derivative of the
dependent function with respect to the independent function.
𝑑𝑦
3𝑥 4𝑦 𝑥 First Order ODE
𝑑𝑥
𝑑 𝑦 Second Order ODE
𝑥 3𝑦 𝑥
𝑑𝑥
Ordinary Differential Equations
2. Linearity: A linear ordinary differential equation has the coefficients of all
derivatives in the standard form either constants or functions of the independent
variable. A standard linear ODE can be expressed as:

𝑑 𝑦 𝑑 𝑦 𝑑𝑦
𝑔 𝑥 𝑔 𝑥 ⋯ 𝑔 𝑥 𝑔 𝑥 𝑦 ℎ 𝑥
𝑑𝑥 𝑑𝑥 𝑑𝑥

𝑑 𝑦 Linear ODE
3𝑥 𝑦 𝑥
𝑑𝑥
𝑑 𝑦 𝑑𝑦 Non-linear ODE
𝑥 𝑦 0
𝑑𝑥 𝑑𝑥
𝑑 𝑦 𝑑𝑦 Non-linear ODE
2 𝑦 𝑥 1 0
𝑑𝑥 𝑑𝑥
Ordinary Differential Equations
An ordinary differential equation with constant coefficients is a special type of linear ordinary
differential equations. And it takes the form:

𝑑 𝑦 𝑑 𝑦 𝑑𝑦
𝐶 𝐶 ⋯ 𝐶 𝐶 𝑦 ℎ 𝑥
𝑑𝑥 𝑑𝑥 𝑑𝑥
An example of such equations:

𝑑 𝑦 𝑑𝑦
6 8𝑦 0
𝑑𝑥 𝑑𝑥
3. Homogeneity: A homogeneous ordinary differential equation has a zero on the right-hand side of
its standard form.

𝑑 𝑦 𝑑 𝑦 𝑑𝑦
𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 ⋯ 𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑦 0
𝑑𝑥 𝑑𝑥 𝑑𝑥
First Order Ordinary Differential Equation
A first order ODE takes the form:
𝑑𝑦
𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑦 ℎ 𝑥, 𝑦
𝑑𝑥
and it requires an initial condition in order to solve for the constant emerging from its
analytical solution.
An example of a first order ODE:
𝑑𝑦
2𝑥 0 𝑦 0 2
𝑑𝑥
First Order Ordinary Differential Equation
This equation can be solved by separation of variables to give:
𝑦 𝑥 𝑥 𝐶
The given initial condition is used to find the constant, 𝐶 and the final solution is:
𝑦 𝑥 𝑥 2

In this chapter, the first order ODE is the basis for applying numerical solutions based
Runge-Kutta methods. Higher order ODE as will be seen later, can be reduced to
systems of first order ODEs.
Heun’s Method
Euler’s method is the basic, first-order Runge-Kutta method which will be used here to
understand the concept behind this method.
Consider the general first order ODE given by:
𝑑𝑦
𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑦 ℎ 𝑥, 𝑦 𝑦 𝑥 𝑦
𝑑𝑥
Which is represented in the figure with the
initial condition, 𝑥 , 𝑦 .

Recall that the value represents the slope of


a function at a given point. Solving for this
value:
𝑑𝑦 ℎ 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑦
𝑑𝑥 𝑔 𝑥, 𝑦
Heun’s Method
Or generally, let’s put:
𝑑𝑦
𝑓 𝑥, 𝑦
𝑑𝑥
Consider now that we slightly move on the function curve in a
path of segment “S” that is small enough to assume the path a
straight line. In this case, the slope of the straight segment
from 𝑥 , 𝑦 to 𝑥 , 𝑦 becomes:
𝑦 𝑦 𝑑𝑦
𝑓 𝑥 ,𝑦
𝑥 𝑥 𝑑𝑥

Which can be evaluated since the point 𝑥 , 𝑦 is already


given as a first condition. Hence, from the same equation, we
can calculate:
𝑦 𝑦 𝑥 𝑥 𝑓 𝑥 ,𝑦
Heun’s Method
𝑦 𝑦 𝑥 𝑥 𝑓 𝑥 ,𝑦
If we let, ℎ 𝑥 𝑥
𝑦 𝑦 ℎ𝑓 𝑥 , 𝑦
The same procedure can be repeated starting from
point 𝑥 , 𝑦 to 𝑥 , 𝑦 by calculating the slope of
the new segment from 𝑓 𝑥 , 𝑦 , as shown in the
figure.
The same can be repeated for the next points
using:
𝑦 𝑦 ℎ 𝑓 𝑥 ,𝑦
Which is Runge-Kutta first order method, known as
Euler’s method.
Heun’s Method
Example 1: Develop a numerical solution to the following ODE, from 𝑥 0 to 𝑥 5,
using a step-size ℎ 0.5.
Compare your solution to the analytical solution: 𝑦 𝑥 𝑥 2.
𝑑𝑦
2𝑥 0 𝑦 0 2
𝑑𝑥
Euler’s Method
Solution:
From the given ODE:
𝑓 𝑥 ,𝑦 2𝑥
Starting with 𝑥 0 and 𝑦 2, and by using Euler’s method
𝑦 𝑦 ℎ 𝑓 𝑥 ,𝑦
𝒚𝒊 𝟏 𝒚𝒊 𝟐𝒉𝒙𝒊
The following table shows both the numerical and analytical 𝑖 𝑥 𝑦 𝑦
0 0 2 2
solution. The numerical solution can be improved by using a 1 0.5 2 2.25
smaller step size ℎ. 2 1 2.5 3
3 1.5 3.5 4.25
4 2 5 6
5 2.5 7 8.25
Euler’s Method
The following figure shows the analytical solution and the numerical solutions based
on ℎ 0.5 and ℎ 0.25.

It is obvious that the step-size can improve the solution.


Programming Task …

Develop a Matlab code that solves Example


1.
Compare the numerical solution with the
analytical one on a single plot.
Heun’s Method
As shown in the introduction to Euler’s method, the accuracy of the method is based on the accuracy
at which the slope of the segment is estimated. Euler’s method is based on estimating the slope of the
segment from a single point, Heun’s method introduces further improvement by basing the estimate of
the slope on two points: at the start point and the end point and hence it takes two steps:
Predictor: 𝑦 𝑦 𝑓 𝑥 ,𝑦 ℎ
, ,
Corrector: 𝑦 𝑦 ℎ

The predictor point 𝑥 , 𝑦 is developed using


Euler’s method and its purpose is to allow
calculating the slope at the end point before
correcting it by using the average of the two
slopes.
Heun’s Method
Example 2: Solve the following ODE using Heun’s method, from 𝑥 0 to 𝑥 4 with
step size, ℎ 1.
.
𝑦 0.5𝑦 4𝑒 𝑦 0 2
Heun’s Method
Solution:
The standard form of the slope:
𝑑𝑦 .
𝑓 𝑥, 𝑦 𝑦 4𝑒 0.5𝑦
𝑑𝑥
From 𝑥 0 to 𝑥 4, ℎ 1, 𝐼. 𝐶. → 𝑥 0, 𝑦 2
𝑓 𝑥 ,𝑦 𝑦 4𝑒 0.5 2 3
𝑦 𝑦 𝑓 𝑥 ,𝑦 ℎ 2 3∗1 5
.
𝑓 𝑥 ,𝑦 4𝑒 0.5 ∗ 5 6.40216
𝑓 𝑥 ,𝑦 𝑓 𝑥 ,𝑦 6.40216 3
𝑦 𝑦 ℎ 2 6.70108
2 2
𝑦 6.70108 5.551623 ∗ 1 12.2527
𝑓 𝑥 ,𝑦 4𝑒 ∗ . 0.5 ∗ 12.2527 13.68578
6.40216 13.68578
𝑦 6.70108 ∗ 1 16.31978
2
Heun’s Method
The following table shows the solution of the ODE using Euler’s, Heun’s and analytical solutions which is given by:

40 .
14 .
𝑦 𝑥 𝑒 𝑒
13 13

Analytical Heun’s Euler’s


𝑖 𝑥 𝑦 𝑓 𝑥 ,𝑦 𝑦 𝑓 𝑥 ,𝑦 𝑦 Error (%) 𝑦 Error
0 0 2 ‐ ‐ ‐ 2 ‐ 2 ‐
1 1 6.194631 3 5 6.402164 6.701082 8.18 5 19.28
2 2 14.84392 5.551623 12.2527 13.68578 16.31978 9.94 11.40216 23.19
3 3 33.67717 11.65224 27.97202 30.1067 37.19925 10.46 25.51321 24.24
4 4 75.33896 25.49308 62.69233 66.78396 83.33777 10.62 56.84931 24.54

Although the same step size is used in both methods, Heun’s method presents more accurate values because of the
better approximation of the slope,𝑓 𝑥, 𝑦 , and since this approximation is based on two points, Heun’s method is
regarded a second-order Runge-kutta method.
Programming Task …

Develop a Matlab code that solves Example


2.
Compare the numerical solution using
Euler’s and Heun’s with the analytical one
on a single plot.
The Midpoint Method
Another second-order Runge-Kutta method is the Midpoint Method which, instead of
using 𝑦 for finding a better estimate for the slope, a point half-way is used, 𝑦 . ,
or the slope at the midpoint of the interval to represent the slope of the whole
interval.

𝑓 𝑥 ,𝑦 ℎ
𝑦 𝑦
2
𝑦 𝑦 𝑓 𝑥 ,𝑦 ℎ
General Runge‐Kutta Methods
The general representation of Runge-Kutta methods have the following form
𝑦 𝑦 𝜙 𝑥, 𝜙 , ℎ ℎ
𝜙 is the increment function which represents the combination of the gradient calculations at different points:
𝜙 𝑎 𝑘 𝑎 𝑘 ⋯ 𝑎 𝑘
𝑎 is constant and ∑ 𝑎 1.
𝑘 𝑓 𝑥 ,𝑦
𝑘 𝑓 𝑥 𝑝 ℎ, 𝑦 𝑞 𝑘 ℎ
𝑘 𝑓 𝑥 𝑝 ℎ, 𝑦 𝑞 𝑘 ℎ 𝑞 𝑘 ℎ

𝑘 𝑓 𝑥 𝑝 ℎ, 𝑦 𝑞 , 𝑘 ℎ 𝑞 , 𝑘 ℎ ⋯ 𝑞 , ,𝑘 ,ℎ

𝑝’s and 𝑞’s are constant. The value of 𝑛 represents the term used in Taylor series to represent the slope and so the
higher 𝑛 used, the less error we get for our approximation.
2nd Order Runge‐Kutta Methods
𝑦 𝑦 𝑎 𝑘 𝑎 𝑘 ℎ With this, we can assume a value for 𝑎 :
𝑘 𝑓 𝑥 ,𝑦
𝑘 𝑓 𝑥 , 𝑝 ℎ, 𝑦 𝑞 𝑘 ℎ For 𝑎 1/2, Heun’s method with a single
𝑎 𝑎 1 corrector
1 1 1
𝑎 𝑝 𝑦 𝑦 𝑘 𝑘 ℎ
2 2 2
1 𝑘 𝑓 𝑥 ,𝑦
𝑎 𝑞
2 𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
𝑎 1 𝑎
1
𝑝 𝑞
2𝑎
2nd Order Runge‐Kutta Methods
For 𝑎 1, Midpoint method
𝑦 𝑦 𝑘 ℎ
𝑘 𝑓 𝑥 ,𝑦
1 1
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
2 2
For 𝑎 2/3, Ralston’s method
1 2
𝑦 𝑦 𝑘 𝑘 ℎ
3 3
𝑘 𝑓 𝑥 ,𝑦
3 3
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
4 4
2nd Order Runge‐Kutta Methods
Example 3: Use Ralston’s and Midpoint to solve
𝑑𝑦
𝑓 𝑥, 𝑦 2𝑥 12𝑥 20𝑥 8.5
𝑑𝑥
From 𝑥 0 to 𝑥 4, ℎ 0.5, 𝐼. 𝐶 → 𝑥 0, 𝑦 1
2nd Order Runge‐Kutta Methods
Solution
Midpoint
𝑘 2 0 12 0 20 0 8.5 8.5
𝑘 2 0.25 12 0.25 20 0.25 8.5 4.21875
𝑦 0.5 1 4.21875 0.5 3.109375 𝜖 3.4%
Ralston
𝑘 2 0 12 0 20 0 8.5 8.5
𝑘 2 0.375 12 0.375 20 0.375 8.5 2.58203125
1 2
𝑦 1 8.5 2.58203125 ∗ 0.5 3.27734375
3 3
3rd Order Runge‐Kutta 4th Order Runge‐Kutta
Methods Methods
1 1
𝑦 𝑦 𝑘 4𝑘 𝑘 𝑦 𝑦 𝑘 2𝑘 2𝑘 𝑘 ℎ
6 6
𝑘 𝑓 𝑥 ,𝑦 𝑘 𝑓 𝑥 ,𝑦

1 1 1 1 1
𝑘 𝑓 𝑥 ℎ, 𝑦 ℎ, 𝑦 𝑘 ℎ 𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
2 2 2 2 2
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ 2𝑘 ℎ 1 1
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
2 2
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
Higher‐Order Runge‐Kutta Methods
1
𝑦 𝑦 7𝑘 32𝑘 12𝑘 32𝑘 76𝑘 ℎ
90
𝑘 𝑓 𝑥 ,𝑦

1 1
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ
4 4

1 1 1
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ 𝑘
4 8 8

1 1
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ 𝑘 ℎ
2 2

3 3 9
𝑘 𝑓 𝑥 ℎ ,𝑦 𝑘 ℎ 𝑘 ℎ
4 16 10
3 12 12 8
𝑘 𝑓 𝑥 ℎ, 𝑦 𝑘 ℎ 𝑘 ℎ 𝑘 ℎ 𝑘 ℎ
7 7 7 7
Higher‐Order Runge‐Kutta Methods
A system of N first-order ordinary differential equations with N initial conditions can
be expressed as a set of equations:
𝑑𝑦
𝑓 𝑥, 𝑦 , 𝑦 , … , 𝑦 𝑦 𝑥 𝐴
𝑑𝑥
𝑑𝑦
𝑓 𝑥, 𝑦 , 𝑦 , … , 𝑦 𝑦 𝑥 𝐴
𝑑𝑥
𝑑𝑦
𝑓 𝑥, 𝑦 , 𝑦 , … , 𝑦 𝑦 𝑥 𝐴
𝑑𝑥
In developing the values of dependent variables, the same procedure is used
Higher‐Order Runge‐Kutta Methods
So, for Euler’s method
We follow the same procedure, so for Euler’s Method:
𝑦 , 𝑦 , ℎ𝑓 𝑥 , 𝑦 , , 𝑦 , , … , 𝑦 ,

𝑦 , 𝑦 , ℎ𝑓 𝑥 , 𝑦 , , 𝑦 , , … , 𝑦 ,

𝑦 , 𝑦 , ℎ𝑓 𝑥 , 𝑦 , , 𝑦 , , … , 𝑦 ,

This procedure will be useful in solving higher order ODE using Runge-Kutta method.
Higher‐Order Runge‐Kutta Methods
Consider the case of a second-order differential equation:

𝑔 𝑥, 𝑦 ℎ 𝑥, 𝑦 0 (1)

Let 𝑧 in (1), and hence . With these substitutions equation


(1) can be reduced to a system of first order linear equations.

𝑧 (2.a)

𝑔 𝑥, 𝑦 ℎ 𝑥, 𝑦 (2.b)
Higher‐Order Runge‐Kutta Methods
Example (4): Use Euler’s method to solve the following ordinary second-order
differential equation that has the initial conditions 𝑦 0 3 and 𝑦 0 1. Find the
solution from t=0 to t=2 with h=0.1.

𝑑 𝑦 𝑑𝑦
4 4𝑦 0
𝑑𝑡 𝑑𝑡
Higher‐Order Runge‐Kutta Methods
Solution
𝑑 𝑦 𝑑𝑦
4 4𝑦 0
𝑑𝑡 𝑑𝑡
Let 𝑧 , the system of first order differential equations will be:

𝑧 → 4𝑧 4𝑦
With the initial conditions 𝑦 0 3 and 𝑧 0 1.
Euler’s equation for the two equations will be:
𝑦 𝑦 0.1 𝑧
𝑧 𝑧 0.1 4𝑧 4𝑦
With 𝑦 3 and 𝑧 1.
Higher‐Order Runge‐Kutta Methods
Recall from the Differential Equations course that the analytical solution of this ODE
which is linear, homogeneous with constant coefficients is:
𝑦 𝑡 𝑐 𝑐 𝑡 𝑒 Whereas c1 and c2 are constants evaluated using the initial
conditions to be 3 and -5 respectively. Hence, 𝑦 𝑡 3 5𝑡 𝑒
Table 1 shows the numerical solution of y along with the analytical one for ℎ=0.1
𝑡 z 𝑦 𝑦 𝑡 z 𝑦 𝑦
0 1 3 3 1.1 ‐60.679 ‐11.7643 ‐22.5625
0.1 0.2 3.1 3.053507 1.2 ‐80.2449 ‐17.8322 ‐33.0695
0.2 ‐0.96 3.12 2.983649 1.3 ‐105.21 ‐25.8567 ‐47.1231
0.3 ‐2.592 3.024 2.733178 1.4 ‐136.951 ‐36.3777 ‐65.7786
0.4 ‐4.8384 2.7648 2.225541 1.5 ‐177.181 ‐50.0728 ‐90.3849
0.5 ‐7.87968 2.28096 1.359141 1.6 ‐228.024 ‐67.7909 ‐122.663
0.6 ‐11.9439 1.492992 0 1.7 ‐292.117 ‐90.5933 ‐164.803
0.7 ‐17.3187 0.298598 ‐2.0276 1.8 ‐372.727 ‐119.805 ‐219.589
0.8 ‐24.3656 ‐1.43327 ‐4.95303 1.9 ‐473.895 ‐157.078 ‐290.558
0.9 ‐33.5386 ‐3.86984 ‐9.07447 2 ‐600.622 ‐204.467 ‐382.187
1 ‐45.4061 ‐7.22369 ‐14.7781
Higher‐Order Runge‐Kutta Methods
Figure 1 shows the deviation of the numerical solution from the exact one. The
accumulative nature of the error results increasing divergence as the curve shifts
away from the initial condition.
50
Numerical
0 Exact

-50

-100

-150
y

-200

-250

-300

-350

-400
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t
Figure 1 The deviation of the numerical solution from the exact one
Higher‐Order Runge‐Kutta Methods
Figure 2 and figure 3 shows the solution when ℎ is set to 0.01 and 0.001 respectively.
At the latter value the two solutions are almost exactly equivalent.
50 50
Numerical Numerical
0 Exact 0 Exact

-50 -50

-100 -100

-150 -150

y
y

-200 -200

-250 -250

-300 -300

-350 -350

-400 -400
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t t

Figure 2 The deviation of the numerical solution from the Figure 2 The deviation of the numerical solution from the
exact one when h=0.01 exact one when h=0.001
Programming Task …

Develop a Matlab code that solves Example


4.
Compare the numerical solution using
Euler’s and Heun’s with the analytical one
on a single plot.
Higher‐Order Runge‐Kutta Methods
Example (5): Use Euler’s method to solve the following system of ODE
𝑑𝑦
0.5𝑦
𝑑𝑥
𝑑𝑦
4 0.3𝑦 0.1𝑦
𝑑𝑥
At 𝑥 0 𝑦 4 𝑦 6
Higher‐Order Runge‐Kutta Methods
Solution:

𝑦 0.5 4 0.5 ∗ 4 0.5 3


𝑦 0.5 6 4 0.3 ∗ 6 0.1 ∗ 4 0.5 6.9

𝒙 𝒚𝟏 𝒚𝟐
0 4 6
0.5 3 6.9
1.0 2.25 7.715
1.5 1.6875 8.44525
2.0 1.265625 9.094087
Higher‐Order Runge‐Kutta Methods
Consider the general second order ODE:

𝑑 𝑦 𝑑𝑦
𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 ℎ 𝑥, 𝑦 𝑦 𝑥 𝐴 𝑦 𝑥 𝐵
𝑑𝑥 𝑑𝑥
Note that the number of provided conditions must equal to the order of the ODE. In order to apply Runge-Kutta
methods on an Nth-Order higher order ODE, it must be reduced to a system of N first-order ODEs:
For the given second-order ODE:
Let:

𝑑𝑦
𝑧 1
𝑑𝑥
Which implies

𝑑𝑧 𝑑 𝑦
2
𝑑𝑥 𝑑𝑥
Higher‐Order Runge‐Kutta Methods
Substituting both in the original equation:
𝑑𝑧
𝑔 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑧 𝑔 𝑥, 𝑦 ℎ 𝑥, 𝑦 𝑦 𝑥 𝐴 𝑧 𝑥 𝐵 3
𝑑𝑥

Solving for from (1) and for from (3) and setting the appropriate initial
conditions, the equivalent system of first-order ODE is:

𝑑𝑦 𝑦 𝑥 𝐴
𝑓 𝑥, 𝑦, 𝑧 𝑧
𝑑𝑥
𝑑𝑧 ℎ 𝑥, 𝑦 𝑔 𝑥, 𝑦 𝑧 𝑔 𝑥, 𝑦 𝑧 𝑥 𝐵
𝑓 𝑥, 𝑦, 𝑧
𝑑𝑥 𝑔 𝑥, 𝑦
Higher‐Order Runge‐Kutta Methods
Example (6): Using higher order R-K methods for higher order ordinary differential
equation:
Solve the following ODE up to x=10 using h=0.5 by using 2nd order R-K method.

𝑑 𝑦 𝑑𝑦
𝑦 3𝑥 𝑦 𝑥 1 𝑦 0 1 𝑦 0 0.5
𝑑𝑥 𝑑𝑥
Higher‐Order Runge‐Kutta Methods
1. Reduce the second-order ODE to a system of two first-order ODE:
Let 𝑧 and substitute it in the given ODE:
𝑑𝑧
𝑦 3𝑥𝑧 𝑦 𝑥 1
𝑑𝑥

2. Define the system of the first-order ODE with their corresponding initial values:

𝑑𝑦 𝑑𝑦
𝑧 𝑦 0 1 𝑙𝑒𝑡 𝑓 𝑥, 𝑦, 𝑧
𝑑𝑥 𝑑𝑥
𝑑𝑧 𝑥 1 𝑦 3𝑥𝑧 𝑑𝑧
𝑧 0 0.5 𝑙𝑒𝑡 𝑔 𝑥, 𝑦, 𝑧
𝑑𝑥 𝑦 𝑑𝑥
Higher‐Order Runge‐Kutta Methods
3. Define the iterative equations for each dependent variable (y and z) in the system:
𝑘, 𝑓 𝑥 ,𝑦 ,𝑧 𝑘 , 𝑔 𝑥 ,𝑦 ,𝑧
𝑘 , 𝑓 𝑥 0.5ℎ, 𝑦 0.5 𝑘 , ℎ, 𝑧 0.5 𝑘 , ℎ 𝑘 ,
𝑔 𝑥 0.5ℎ, 𝑦 0.5 𝑘 , ℎ, 𝑧 0.5 𝑘 , ℎ
𝑦 𝑦 𝑘 , ℎ 𝑧 𝑧 𝑘 , ℎ
Higher‐Order Runge‐Kutta Methods
i xi k1,y K1,z xi+0.5 h yi+0.5k1,y h zi+0.5k1,z h K2,y K2,z zi yi
0 0 ‐ ‐ ‐ ‐ ‐ ‐ ‐ 0.5 1
1 0.5 0.500 0.000 0.250 1.125 0.500 0.500 0.056 0.528 1.250
2 1 0.528 0.167 0.750 1.382 0.569 0.569 0.289 0.672 1.535
3 1.5 0.672 0.292 1.250 1.703 0.745 0.745 0.332 0.838 1.907
4 2 0.838 0.299 1.750 2.117 0.913 0.913 0.308 0.992 2.364
5 2.5 0.992 0.289 2.250 2.612 1.064 1.064 0.293 1.139 2.896
6 3 1.139 0.281 2.750 3.181 1.209 1.209 0.285 1.281 3.501
7 3.5 1.281 0.276 3.250 3.821 1.350 1.350 0.281 1.422 4.176
8 4 1.422 0.274 3.750 4.531 1.490 1.490 0.279 1.561 4.921
9 4.5 1.561 0.273 4.250 5.311 1.630 1.630 0.277 1.700 5.736
10 5 1.700 0.272 4.750 6.161 1.768 1.768 0.277 1.838 6.620
11 5.5 1.838 0.272 5.250 7.080 1.907 1.907 0.276 1.977 7.573
12 6 1.977 0.273 5.750 8.067 2.045 2.045 0.276 2.114 8.596
13 6.5 2.114 0.273 6.250 9.124 2.183 2.183 0.276 2.252 9.687
14 7 2.252 0.273 6.750 10.250 2.320 2.320 0.275 2.390 10.847
15 7.5 2.390 0.273 7.250 11.445 2.458 2.458 0.275 2.528 12.076
16 8 2.528 0.274 7.750 12.708 2.596 2.596 0.275 2.665 13.374
17 8.5 2.665 0.274 8.250 14.041 2.734 2.734 0.275 2.803 14.741
18 9 2.803 0.274 8.750 15.442 2.871 2.871 0.275 2.940 16.177
19 9.5 2.940 0.274 9.250 16.912 3.009 3.009 0.275 3.078 17.681
20 10 3.078 0.274 9.750 18.451 3.147 3.147 0.275 3.216 19.254
Higher‐Order Runge‐Kutta Methods
Exercise: For the ordinary differential equation:
𝑑 𝑦 𝑑𝑦 𝑦 sin 𝑥 20 .
1
𝑥 𝑒 1.001 10
𝑑𝑥 𝑑𝑥 𝑥 𝑥 𝑥 𝑥

𝑦 1 17.1485 𝑦 1 2.5504 𝑦 1 1.1586

a) Prove that 𝑦 𝑥 𝑥 sin 𝑥 𝑒 . 20 is an exact solution to the given ODE.


b) Solve the given ODE up to x=10 using:
1. Euler’s Equation
2. Third order Runge-Kutta methods
Compare each solution with the exact one for different values of h.
Summary

You might also like