You are on page 1of 10

A PROJECT REPORT On

Numerical solutions of ordinary differential equation using runge kutta method

Submitted by: RENUKA BOKOLIA Research Scholar

Numerical Solution of Ordinary Differential Equations (ODE)

I. Definition An equation that consists of derivatives is called a differential equation. Differential equations have applications in all areas of science and engineering. Mathematical formulation of most of the physical and engineering problems lead to differential equations. Differential equations are of two types 1) ordinary differential equation (ODE) 2) partial differential equations (PDE). An ordinary differential equation is that in which all the derivatives are with respect to a single independent variable. Examples of ordinary differential equation include 1) 2) So, it is important for engineers and scientists to know how to set up differential equations and solve them.

d2y dy dy + 2 + y = 0 , (0) = 2, y (0) = 4 , 2 dx dx dx


dy d3y d2y dy d2y (0) = 2 , y (0) = 4 + 3 + 5 + y = sin x , (0) = 12, 3 2 2 dx dx dx dx dx

Note: In this part, we will see how to solve ODE of the form

dy = f (x, y ), y (0) = y 0 dx
II. Eulers Method

We will use Eulers method to solve an ODE under the form:

dy = f (x, y ), y (0) = y 0 dx

x = 0 , we are given the value of y = y 0 . Let us call x = 0 as x 0 . Now since we know the slope of y with respect to x , that is, f (x, y ) , then at x = x0 , the slope is f (x0 , y 0 ). Both x 0 and y 0 are known from the initial condition y (x0 ) = y 0 .
At

True value y1, Predicted value

x0,y0

Step size, h x

Figure 1.Graphical interpretation of the first step of Eulers method.

So the slope at x=x0as shown in the figure above Slope

y1 y0 x1 x0 = f (x 0 , y 0 ) =

Thus

y1 = y0 + f (x0 , y0 ) (x1 x0 )
If we consider

x1 x0 as a step size h , we get

y1 = y0 + f (x0 , y0 ) h .
We are able now to use the value of is the predicted value at

y1 (an approximate value of y at x = x1 ) to calculate y 2 , which

x2 , y2 = y1 + f (x1, y1 ) h
y = yi at xi , then

x2 = x1 + h
Based on the above equations, if we now know the value of

yi +1 = yi + f (xi , yi ) h
This formula is known as the Eulers method and is illustrated graphically in Figure 2. In some books, it is also called the Euler-Cauchy method.

True Value

yi+1, Predicted value yi h Step size xi xi+1 x

Figure 2. General graphical interpretation of Eulers method.

It can be seen that Eulers method has large errors. This can be illustrated using Taylor series.
2 3 dy y (xi +1 xi ) + 1 d 2 (xi +1 xi )2 + 1 d y (xi +1 xi )3 + ... 3 dx , yi 2! dx , y 2 1 3! dx , y 1 3 i i i yi +1 = yi + f ( xxii , yi ) + f ' ( xi , yi )(xi +x f ' ' ( xi , yi )(xxii+ 1 xi ) + 1 xi ) + ... 2! 3!

yi +1 = yi +

As you can see the first two terms of the Taylor series

yi +1 = yi + f (xi , yi )h are the Eulers method.

The true error in the approximation is given by

Et =

f (xi , yi ) 2 f (xi , yi ) 3 h + h + ... 2! 3!

The true error hence is approximately proportional to the square of the step size, that is, as the step size is halved, the true error gets approximately quartered. However from Table 1, we see that as the step size gets halved, the true error only gets approximately halved. This is because the true error being proportioned to the square of the step size is the local truncation error, that is, error from one point to the next. The global truncation error is however proportional only to the step size as the error keeps propagating from one point to another.

II. Runge-Kutta 2

nd

order

Eulers method was derived from Taylor series as:

yi +1 = yi + f (xi , yi )h
This can be considered to be Runge-Kutta 1 order method. The true error in the approximation is given by
st

Et =

f (xi , yi ) 2 f (xi , yi ) 3 h + h + ... 2! 3!


nd

Now let us consider a 2

order method formula. This new formula would include one more term of

the Taylor series as follows:

yi +1 = yi + f (xi , yi )h + dy = e 2 x 3 y, y (0) = 5 dx

1 f (xi , yi )h 2 2!

Let us now apply this to a simple example:

f (x, y ) = e2 x 3 y
Now since y is a function of x,

f (x, y ) =

f (x, y ) f (x, y ) dy + x y dx 2 x ( = (e 2 x 3 y ) + e 3 y ) (e 2 x 3 y ) x y 2 x 2 x = 2e + ( 3) e 3 y

= 5e2 x + 9 y
The 2
nd

order formula would be

yi +1 = yi + f (xi , yi )h + yi +1 = yi + e 2 xi
Kutta did was write the 2
nd

1 f (xi , yi )h 2 2! 1 3 yi h + 5e 2 xi + 9 yi h 2 2!

You could easily notice the difficulty of having to find order method as

f (x, y ) in the above method.

What Runge and

yi +1 = yi + (a1k1 + a2 k 2 )h
where

k1 = f (xi , yi ) k2 = f (xi + p1h, yi + q11k1h )


This form allows us to take advantage of the 2 But, how do we find the unknowns a1 ,
nd

order method without having to calculate

f (x, y ).

a2 , p1 and q11 ? Equating the above equations:

yi +1 = yi + f (xi , yi )h +
gives three equations.

1 f (xi , yi )h 2 and yi +1 = yi + (a1k1 + a2 k 2 )h 2!

a2 p1 =

1 2

a1 + a2 = 1
1 2

a2q11 =

Since we have 3 equations and 4 unknowns, we can assume the value of one of the unknowns. The other three will then be determined from the three equations. Generally the value of a2 is chosen to evaluate the other three constants. The three values generally used for

a2 are

1 2 , 1 and , and are 2 3

known as Heuns Method, Midpoint method and Ralstons method, respectively. II.1. Heuns method Here we choose a2

1 , giving 2

a1 =

1 2

p1 = 1 q11 = 1
resulting in

1 1 yi +1 = yi + k1 + k2 h 2 2
where

k1 = f (xi , yi ) k 2 = f (xi + h, yi + k1h)


This method is graphically explained in Figure 6.

Slope = f (xi + h, yi + k1h ) Slope = f (xi , yi )


yi+1, predicted

Average Slope =
yi

1 [ f (xi + h, yi + k1h ) + f (xi , yi )] 2

xi

xi+1

Figure 6.Runge-Kutta 2 order method(Heuns method).

nd

II.2. Midpoint method Here we choose a2

= 1, giving

a1 = 0
p1 =

1 2 1 q11 = 2

resulting in

yi +1 = yi + k2h
where

k1 = f (xi , yi ) 1 1 k 2 = f xi + h, yi + k1h 2 2
II.3. Ralstons method Here we choose

a2 =

2 , giving 3

a1 =

1 3 3 p1 = 4 3 q11 = 4 1 2 yi +1 = yi + ( k1 + k 2 )h 3 3

resulting in

where

k1 = f (xi , yi ) 3 3 k 2 = f xi + h, yi + k1h 4 4

NOTE: How do these three methods compare with results obtained if we found

f (x, y ) directly?

We know that since we are including first three terms in the series, if the solution is a polynomial of order two or less (that is, quadratic, linear or constant), any of the three methods are exact. But for any other case the results will be different. Consider the following example

dy = e 2 x 3 y, y (0) = 5 dx
If we directly find the

f (x, y ), the first three terms of Taylor series gives


1 f (xi , yi )h 2 2!

yi +1 = yi + f (xi , yi )h +
where

f (x, y ) = e2 x 3 y f (x, y ) = 5e2 x + 9 y

For a step size of h = 0.2 , using Heuns method, we find

y(0.6) = 1.0930
The exact solution 2 x

y(x ) = e

+ 4e3x

gives

y(0.6) = e2(0.6) + 4e3(0.6) = 0.96239


Then the absolute relative true error is

t =

0.96239 1.0930 100 0.96239 = 13.571%

For the same problem, the results from the Euler and the three Runge-Kuttamethod are given below Comparison of Eulers and Runge-Kutta 2 y(0.6) Exact Value 0.96239 Euler 0.4955 48.514 Direct 2nd 1.0930 13.571 Heun 1.1012 14.423 Midpoint 1.0974 14.029 Ralston 1.0994 14.236
nd

order methods

III. Runge-Kutta 4 order Runge-Kutta 4 order method is based on the following


th

th

yi +1 = yi + (a1k1 + a2k2 + a3k3 + a4k4 )h


where knowing the value of

y = yi at xi , we can find the value of y=yi+1 at xi +1 , and

h = xi +1 xi
The above equation is equated to the first five terms of Taylor series

yi +1 = yi + + 1d y 4! dx 4
4

dy dx

1d x , y (xi +1 xi ) +
i i

y
2

2! dx

1d 2 x , y (xi +1 xi ) +
i i

y
3 xi , y i

3! dx

(xi +1 xi )

xi , y i

(xi +1 xi )4

Knowing that

dy = f (x, y ) and xi +1 xi = h dx 1 1 1 yi +1 = yi + f (xi , yi )h + f ' (xi , yi )h 2 + f '' (xi , yi )h3 + f ''' (xi , yi )h 4 2! 3! 4!

Based on equating the above equations, one of the popular solutions used is

yi +1 = yi +

1 (k1 + 2k2 + 2k3 + k4 )h 6

of the interval [xi,xi+1] using the Euler method to predict the y approximation there. 1 1 k3 = f xi + h, yi + k2 h This is an Improved Euler approximation for the slope at 2 2
the midpoint.

k1 = f (xi , yi ) This is the slope at xi. 1 1 k2 = f xi + h, yi + k1h This is an estimate of the slope at the midpoint 2 2

k4 = f (xi + h, yi + k3h)This is the Euler method slope at xi+1, using the


Improved Euler slopek3at the midpoint to step to xi+1.

Errors There are two main sources of the total error in numerical approximations: 1. The global truncation error arises from the cumulative effect of two causes: At each step we use an approximate formula to determine yn+1 (leading to a local truncation error). The input data at each step are only approximately correct since in general (tn) yn. 2. Round-off error, also cumulative, arises from using only a finite number of digits.

It can be shown that the global truncation error for the Euler method is proportional to h, for the Improved Euler method is proportional to h2, and for the RungeKutta method is proportional to h4.

You might also like