You are on page 1of 13

PROJECT REPORT

AML 702
(APPLIED COMPUTATIONAL METHODS)

COMPARISON OF RUNGE KUTTA METHODS

Submitted by
ANANTH KISHORE (2018AMX5503)
ARPIT TRIVEDI (2018AMX5504)
RAHUL THAKUR (201AMX5517)

Under the guidance of

Vamsi K Chalamalla
Assistant Professor

DEPARTMENT OF APPLIED MECHANICS

INDIAN INSTITUTE OF TECHNOLOGY DELHI

HAUZ KHAS, NEW DELHI-110016

MAY 2019

1
TABLE OF CONTENT

S. NO. TOPIC PAGE NO.


01. Abstract 3

02. Introduction 4

03. Problem Definition 9

04. Results and Discussions 10

05. References 13

2
ABSTRACT

The paper deals with a MATLAB algorithm for implementation of Runge-


Kutta methods of order 4, 5 and 6. The running time and maximum errors for
the methods are compared for a set of ordinary differential equation.

3
CHAPTER 1
INTRODUCTION

NUMERICAL SOLUTIONS
Numerical methods for ordinary differential equations are methods used to
find numerical approximations to the solutions of ordinary differential
equations (ODEs). Their use is also called as "numerical integration.
Many differential equations cannot be solved using symbolic
computation ("analysis"). For practical purposes, such as in engineering – a
numeric approximation to the solution is often sufficient.
The algorithms studied here can be used to compute such an approximation.
Ordinary differential equations occur in many scientific disciplines, for
instance in physics, chemistry, biology, and economics. In addition, some
methods in numerical partial differential equations convert the partial
differential equation into an ordinary differential equation, which must then
be solved.

Example:
Numerical integration of y’=y at x0 = 0 and y0 =1
By three different methods and results were plotted as shown in figure.
Most of the numerical methods used to solve ode are based directly (or
indirectly) on truncated Taylor series expansion such as:
a) Taylor series methods
b) Runge-kutta methods

TAYLOR SERIES METHOD


The problem to be solved is a first order ode:
dy(x)
= f(x, y), y(x0 ) = y0
dx
Estimates of the solution at different base points
4
y(x0 + h), y(x0 + 2h), y(x0 + 3h), . . ..

Where h is interval and is solved by truncated Taylor series method as


shown:
Truncated taylor series expansion is written as:

dy h 2 d2 y h n dn y
y(x0 + h) ≈ y(x0 ) + h |x=x , + | +. . . + |
dx 0 2! dx 2 x=x0 , n! dx n x=x0 ,
y=y0 y=y0 y=y0

First order Taylor Series Method (Euler method)


dy
y(x0 + h) = y(x0 ) + h |x=x , + o(h2 )
dx 0
y=y0

dy
Notation: xn = x0 + nh, yn = y(xn ), | = f(xi , yi )
dx x=xi ,
y=yi

EulerMethod now can be written as:


yi+1 = yi + hf(xi , yi )

This can be represented graphically as:

Fig 1: Taylor series representation

5
HIGH ORDER TAYLOR SERIES METHODS
Higher order Taylor series methods include higher order derivatives that
provides much more accuracy as compared to first order but the solving of
these derivatives is a tedious task as shown:
Nth order Taylor series as earlier
dy h2 d2 y h n dn y
yi+1 = yi + h + 2
+. . . . + n
+ O(hn+1 )
dx 2! dx n! dx
These derivatives have to be derived analytically-
d2 y d3 y dn y
, ,.....,
dx 2 dx 3 dx n
To solve this problem we use methods like Runge Kutta which don’t require
calculating higher order derivatives.

RUNGE-KUTTA METHODS:
This approach is to formula involving unknown coefficients then determines
these coefficients to match as many terms of the Taylor series expansion as
possible for better accuracy. In this report we will deal with RK 4, RK 5 and
RK 6 methods for solving given set of ODE’s.
Let an initial value problem be specified as follows:
dy
= f(t, y), y(t 0 ) = y0
dt

Then, the RK4 method for this problem is given by the following equations:
1
y(n+1) = yn + h (k1 +2k2 +2 k3 + k4)
6
tn+1 = tn + h
where yn+1 is the RK4 approximation of y(tn+1), and
k1 = f (tn, yn),
k2= f (tn + 0.5h, yn +0.5 hk1),
k3= f (tn + 0.5h, yn +0.5 hk2),
6
k4= f (tn + h, yn +hk3)
Thus, the next value (yn+1) is determined by the present value (yn) plus the
product of the size of the interval (h) and an estimated slope.

The slope is a weighted average of slopes:


a) k1 is the slope at the beginning of the interval;
b) k2 is the slope at the midpoint of the interval, using slope k1 to
determine the value of y at the point tn + h/ 2 using Euler’s method;
c) k3 is again the slope at the midpoint, but now using the slope k2 to
determine the y-value;
d) k4 is the slope at the end of the interval, with its y-value determined
using k3.
e) In averaging the four slopes, greater weight is given to the slopes at
the midpoint:
1
slope = (k1 + 2k2 +2k3 + k4)
6

The RK4 method is a fourth-order method, meaning that the error per step
is on
the order of h5, while the total accumulated error has order h4.
This method is valid for both scalar and vector valued functions.
Similarly the 5th order Runge-Kutta method (RK5) for the same problem is
given by the following equations:

k1 = f (tn, yn),
k2= hf (tn + 0.5h, yn +0.5 k1),
ℎ 3k1+k2
k3= hf (tn + , yn + ),
4 16
k3
k4= hf (tn + 0.5h, yn + ),
2
3ℎ −3k2+6k3+9k4
k5= hf (tn + , yn + ),
4 16
k1+4k2+6k3−12k4+8k5
k6= hf (tn +h, yn + ),
2
7k1 +32k3 +12k4 + 32k5+7k6
and y(n+1) = yn + h ( )
90
7
Similarly, RK 6 method is given as:
yn+1 = yn + {9k1 + 64k2 + 49k5 + 49k6 + 9k7}/180
k1 = f (tn, yn),
k2= hf (tn + vh, yn +v k1),
ℎ (4𝑣−1)k1+k2
k3= hf (tn + , yn + ),
2 8𝑣
k3
k4= hf (tn + 0.5h, yn + ),
2
3ℎ −3k2+6k3+9k4
k5= hf (tn + , yn + ),
4 16
k1+4k2+6k3−12k4+8k5
k6= hf (tn +h, yn + ),
2

8
CHAPTER 2

PROBLEM DEFINITION

Solve the following problem using RK method of order 4, 5 and 6 and


thereafter compare the errors and running time of each method.

9
CHAPTER 3

RESULTS AND DISCUSSION

From the given set of equations calculating the eigen value of the jacobian
matrix:
−0.04 0 1
J = [ 0.04 −600 −1 ]
0 600 0
The eigen values are λ= -598.99, 0, -0.0104.

Therefore, λmax= -598.99.

The stability region of the RK4, RK5 and RK6 are therefore plotted here using
a MATLAB algorithm which finds the roots for each of the method’s stability
equation.

As evident from the figure, the region of stability increases as we go for


higher order RK methods. Also, the limiting value of time step increases
which means that we can higher time steps i.e. reduced computational time.

Fig 2: Stability regions of RK Methods

10
From the figure, the stability conditions are:
2.79
a) RK4: h≤ i.e. h ≤ 0.00466
⎹λmax⎹⎸
3.2
b) RK5: h≤ i.e. h ≤ 0.00534
⎹λmax⎹⎸
3.5
c) RK6: h≤ i.e. h ≤ 0.00584
⎹λmax⎹⎸

Using the limiting value of h for all three methods we know compare the
running time and errors of RK4, RK5 and RK6. Since, in this case the true
values are not known hence we assume the values obtained from RK6 as
the true solution. The system of ODE is evaluated at various time steps using
MATLAB and the results are tabulated below.

RK 4 RK 5 RK6

STEP SIZE ERROR TIME ERROR TIME TIME

0.06 unstable unstable unstable

0.001 1.8593 8.78 1.8591 12.11 19.02

0.0001 0.0233 86.8 0.0227 1.25e2 1.58e2

0.0005 0.0117 16.524 0.01132 23.93 32.822

Table 1: Comparison of error and running time (sec) of RK methods

RESULTS

a) As seen from the table the time elapsed increases as order of RK


method increases.
b) However, the error reduces with increased order of RK method.
c) The solution becomes unstable for value of time step greater than the
limiting value.

11
CONCLUSION
It is therefore evident from the table that the no significant accuracy is
obtained by using RK5 and RK6 as compared to their running time. Hence,
it can be said that RK4 gives us the best balance between accuracy and
computational cost.

Fig 3: RK4 unstable for h = 0.06 Fig 4: RK4 result

Fig 5: RK5 result Fig 6: RK6 result

12
CHAPTER 4

REFERENCES

1. Parviz Moin (2010), Fundamentals of Engineering Numerical Analysis.


2. Steven C. Chapra (2012), Applied Numerical Methods with MATLAB
with engineers and scientists.

13

You might also like