Vous êtes sur la page 1sur 8

Lecture Note 9

Ordinary Differential Equation (ODE)


9.1. Solution of ODE using Runge-Kutta method first order
Differentiation is generally expressed as follows :

dy
dy
= y' ( x ) = f ( x , y ) as well as
= y' ( t ) = f ( t , y )
dx
dt

(9-1)

If dx = h, then eq. (9-1) can be modified as

yn +1 = yn + dx y '( x ) = yn + h. f ( x, y )

(9-2)

Eq. (9-2) was considered to be the first order Runge-Kutta. Solution can be obtained
only if the boundary condition (for x) or the initial condition (for t) is given. The
increment of x (i.e. x = h) or the increment of time or time step (i.e. t = h) can be
set based on the nature of the problem, wheter it includes higher accuracy or not.

9.1. Solution of ODE using Runge-Kutta method higher order


The second order of Runge-Kutta method was developed from the first order.
Basically, the second order is subject to two corrections, whereas the first order has
only one element of correction. The second orde Runge-Kuta was expressed as :
yn+1 = yn + ak1 + bk2

(9-3)

where :
k1 = hf (xn, yn)
k2 = hf (xn+ h, yn+ k1)
k2 = hf (xn+h, yn+ k1)
h = xn+1 - xn

Algorithm of second order Runge-Kutta method :


o

For equation :
y = f(x, y)
, y(xo) = yo
a=b=
, ==1
Calculate yn up to y(xo+nh) for constant h and n = 0, 1, 2, using following
equations :
yn+1 = yn + (k1 + k2) with
k1
= hf (xn, yn)
k2
= hf (xn+h, yn+k1)
9-1

Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

Algoritthm of fourth order Runge-Kutta method :


o
o

For equation :
y = f(x, y)
, y(xo) = yo
Calculate yn up to y(xo+nh) for constant h and n = 0, 1, 2, using following
equations :
yn+1 = yn + 1/6 (k1 + 2k2 + 2k3 + k4) with :
(9-4)
k1 = hf (xn, yn)
k2 = hf (xn+ h, yn+ k1)
k3 = hf (xn+ h, yn+ k2)
k4 = hf (xn+h, yn+k3)

Example 1: second order Runge-Kutta :


Given

Give

1
and y(0) = 1
y
: solution within interval x = 0 to x = 1 with h = 0.1

: y' = f ( x , y ) = x

Solution was given in the Table 9-1 and correspondingly depicted by Figure 9.1.
Table 9-1: Solution of example 1

yn

k1

k2

yn+1

0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1

1
0.8944
0.7855
0.6681
0.5321
0.3479
-0.1983
-0.0229
2.2201
2.2554
2.3015

-0.1000
-0.1018
-0.1073
-0.1197
-0.1479
-0.2374
0.5642
4.4387
0.0350
0.0457
0.0566

-0.1111
-0.1162
-0.1275
-0.1524
-0.2203
-0.8551
-0.2133
0.0474
0.0357
0.0465
0.0576

-0.1056
-0.1090
-0.1174
-0.1360
-0.1841
-0.5462
0.1754
2.2430
0.0353
0.0461
0.0571

0.8944
0.7855
0.6681
0.5321
0.3479
-0.1983
-0.0229
2.2201
2.2554
2.3015
2.3586

9-2
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

2.5

yn

1.5

0.5

-0.5
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

xn

Figure 9.1: Solution of example 1

9.3. Solution of ODE using Predictor - Corrector method


Predictor-corrector method was considered to be likely Runge-Kutta with indefinite
correction. The number of correction can be set depending on the accuracy that will
be needed. The predictor-corrector method was based on the polynomial
interpolation within interval between xn+1 and xn that was expressed as :
y n +1 = y n +

h
f ( x n , y n ) + f ( x n +1 , y n +1 )
2

n = 1, 2 , ......

(9-5)

x : independent variable
y : dependent variable
h : xn+1 - xn
Eq. (9-5) is the implicit form for yn+1, since yn+1 appears to be an argument at right
hand side. If f(x,y) is non-linear, then eq. (9-5) can not be closely solved.
Accordingly, yn+1 will be iteratively solved. By introducing the value of xn, the first
estimated value y n(0+)1 on y n + 1 will be obtained based on the first order Runge-Kutta
method as :
y n(0+)1 = y n + hf ( xn , y n )

(9-6)

Subsequenly using f ( x n +1 , y n(0+)1 ) the first iteration will be performed by means


substitution into the eq. (9-5), then will be obtained following equation :
9-3
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

y n(1+)1 = y n +

h
f ( xn , y n ) + f ( xn + 1 , y n(0+)1 )
2

(9-7)

Second iteration will be obtained by means of substitution of f ( x n +1 , y n(1+)1 ) into eq.


(9-7). In general the iteration will be resulted in :
y n(k+)1 = y n +

h
f ( xn , y n ) + f ( xn + 1 , y n(k+11) )
2

k = 1, 2 , ......

(9-8)

The iteration can only be stoped if the level of accuracy has already been achieved.

Algorithm of Predictor Corrector :

Step 1 :

Step 2 :

prediction step (outer iteration)


For n starting from 1 and for equation y' = f(x,y), y(x0) = y0
with h = xn+1 - xn and xn = x0 + nh,
calculate y n(0+)1 using eq. (9-6).
correction step (inner iteration)
For k = 1,2, calculate y n(k+)1 using eq. (9-9), until
following level of accuration is achieved :
y n( k+ 1) y n( k+1 1 )
y n( k+ 1)

<

Repeat step 1 for n = n + 1.

Some of parameters that have to be determined or given in order to solve the


numerical integration based on the predictor-corrector according the algorithm above
are as follows :
-

The value of n (number of outer iteration)


The value of k (number of inner iteration)

Eq. (9-6) is explicit that is called as the the predictor, whereas eq. (9-5) is implicit
and called as the the corrector. If both of them is simultaneously used, then the
corresponding method can be called as the predictor-corrector. The result from the
correction equation of step will always be more accurate than the prediction.

Example 2: implementation of Predictor corrector method


Given
Give
Answer

1
and y(0) = 1
y
: solution within interval from x = 0 to x = 0.2 with h = 0.1
: y'''(0) -2, then the error = -(h3/12)y''' 0.0002
: y' = f ( x , y ) = x

9-4
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

Step 1 :

Step 2 :

for n = 1, from eq. (9-6) will be obtained y1(0 ) = 0.9

from eq. (9-8) will be resulted in y1(1) = 0.8994 and y1(2 ) = 0.8994

Since the value of y1(1) = y1(2 ) = 0.8994 , then the inner iteration was
stoped and results in the value of y1 = 0.8994 that can be used to
compute its derivate as follows :
y 1' = f (x1 , y 1 ) = x1

1
= 1.0118
y1

on x1 = x0 +nh = 0.1

Step 1 :

for n = 2 from eq. (9-6) will be obtained

Step 2:

from eq. (9-6) will be obtained

y 2(0 ) = 0.8994 + 0.1( 01.0118 ) = 0.7982

y 2(1) = 0.8994 + 0.05 1.0118 + 0.2


= 0.7962
0.7982

y 2(2 ) = 0.8994 + 0.05 1.0118 + 0.2


= 0.7960
0.7962

y (3 ) = 0.7960
2

Since y 2(2 ) = y 2(3 ) = 0.7960 , then the iteration was stoped and the value
of y2 = 0.7960 can be used to calculate its derivate, i.e :
y '2 = f ( x 2 , y 2 ) = x 2

1
= 1.0562
y2

on x2 = x0 + nh = 0.2

Level of accuracy of ODE solution using predictor-corrector was indicated by the


number of iteration, especially the inner iteration

9.4. Solution of SODE using Runge-Kutta method


Runge-Kutta method for single ODE can be developed for solution of system of
simultaneous ODE (SODE). Following is the example of development of RungeKutta for second order SODE.
dx
= x 't = f (t , x , y )
dt
dy
= y 't = g (t , x , y )
dt

(9-9)

f and g are function of t, x and y that is usually given. It can subsequently be defined
as follows :
h

= t n +1 t n

x n = x( t n )

(9-10)

y n = y( t n )

with following parameters of the fourth order Runge-Kutta :

9-5
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

k 1 = h f (t n , x n , y n )

l 1 = h g (t n , x n , y n )

(9-11)

k
l
h

k 2 = h f t n + , x n + 1 , y n + 1
2
2
2

k
l
h

l 2 = h g t n + , x n + 1 , y n + 1
2
2
2

(9-12)

k
l
h

k 3 = h f t n + , xn + 2 , y n + 2
2
2
2

k
l
h

l3 = h g t n + , xn + 2 , y n + 2
2
2
2

(9-13)

k 4 = h f (t n + h , x n + k 3 , y n + l 3 )

l 4 = h g (t n + h , x n + k 3 , y n + l 3 )

(9-14)

The value of x and y on tn +1 is :


1
(k 1 + 2k 2 + 2k 3 + k 4 )
6
1
= y n + (l 1 + 2l 2 + 2l 3 + l 4 )
6

x n +1 = x n +
y n +1

(9-15)

Example 3: Solution of SODE using Runge-Kutta method:


Given following diffusion equation. C and t are respectively variable for
concentration and time.
C'' + 2 t C' 0.5 C = 0

(9-16)

Solution interval from t = 0 to t = 0.5 with boundary condition C = 1 and C' = 0.


Answer :
Time step or h was set to be 0.1. The next step is to modify eq. (9-16) to become first
order by means of setting: x = C, y = C', then eq. (9-16) can be modified to become a
pair of following equations :
x' = y
y' = 0.5 x 2ty

(9-17)

With boundary condition x = 1 and y = 0 on t = 0. According to eq (9-9), the f and g


can be defined as :

9-6
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

x ' = f (t , x , y ) = y

(9-18)

y ' = g (t , x , y ) = 0.5 x 2ty

For first approach it will be used t0 = 0, x0 = 1 and y0 = 0. Subsequently by


substitution into eq. (9-12) to eq. (9-14) will be obtained following quantities :
k 1 = 0 .1 x 0 = 0

l 1 = 0 .1 x (0 .5 x 1 2 x 0 x 0 ) = 0 .05
0 .05

k 2 = 0 .1 x 0 +
= 0 .0025
2


0
0 .1
0 .05

l 2 = 0 .1 x 0 .5 1 + 2 0 +
x 0 +
= 0 .04975
2
2
2

0 .04975

k 3 = 0 .1 x 0 +
= 0 .002488
2


0 .0025
0 .1
0 .04975

l 3 = 0 .1 x 0 .5 1 +
2 0 +
x 0 +
= 0 .049814
2
2
2


k 4 = 0 .1 x (0 + 0 .049814 ) = 0 .004981
l 4 = 0 .1 x [0 .5(1 + 0 .002488 ) 2(0 + 0 .1) x (0 + 0 .049814 )] = 0 .049128

That will give the x and y at the next step :


0 + 2 x 0.0025 + 2 x 0.002488 + 0.004981
= 1.002493
6
0.05 + 2 x 0.04975 + 2 x 0.049814 + 0.049128
y1 = 0 +
= 0.049709
6

x1 = 1 +

The next result up to the fifth iteration was given in the following Table.
Tabel 9-2: Iteration Result
n = Iterasi

tn
xn
yn
k1
l1
k2
l2
k3
l3
k4
l4
xn + 1 = C
yn + 1 = C

0
1
0
0
0.0500
0.0025
0.0498
0.0025
0.0498
0.0050
0.0491
1.0025
0.0497

0.1
1.0025
0.0497
0.0050
0.0491
0.0074
0.0480
0.0074
0.0481
0.0098
0.0466
1.0099
0.0977

0.2
1.0099
0.0977
0.0098
0.0466
0.0121
0.0447
0.0120
0.0448
0.0142
0.0425
1.0219
0.1424

0.3
1.0219
0.1424
0.0142
0.0426
0.0164
0.0400
0.0162
0.0401
0.0183
0.0373
1.0382
0.1824

0.4
1.0382
0.1824
0.0182
0.0373
0.0201
0.0343
0.0200
0.0345
0.0217
0.0312
1.0582
0.2167

0.5
1.0582
0.2167
0.0217
0.0312
0.0232
0.0279
0.0231
0.0281
0.0245
0.0247
1.0813
0.2447

9-7
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

9-8
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

Vous aimerez peut-être aussi