You are on page 1of 5

General Runge Kutta Formulas:

k1 = hf (xi; yi )
1 1
k2 = hf (xi + h; yi + k1)
2 2
1 1
k3 = hf (xi + h; yi + k2)
2 2
k4 = hf (xi + h; yi + k3)
1 1 1 1
yi+1 = yi + k1 + k2 + k3 + k4
6 3 3 6
Example 1 Let’s illustrate a dynamical system using h, with
a 4th order RK numerical solution, then we will compare
with the actual exact solution. What is this dynamic sys-
tem?
dz1
x =y dt = z2
0

dz2
y = ¡x = ¡z1
0

or dt ;
x(0) = 0 z1(0) = 0
y(0) = 1 z2(0) = 1
Note in our RK equations above, we advance ahead by
incrementing xi by stepsize (typically for dynamic systems
we call this time) and calculating incremental values to yi.
In our problem yi is a vector of solutions (or trajectories
over time, one for each 1st ODE) we’re trying to calculate.
So in our problem we have two trajectories z2(t) and z1(t):
so let · ¸
z1
yi of RK formulas= vector zi =
z2
xi of RK formulas=ti
k1 = hf (ti; zi);
k2 = hf (ti + 12 h; zi + 12 k1);
k3 = hf (ti + 12 h; zi + 12 k2);
k4 = hf (ti + h; zi + k3);
zi+1 = zi + 16 k1 + 13 k2 + 13 k3 + 16 k4 · ¸
y(0)
Here f (ti; zi) = f (zi ); and f (z0) =
¡x(0)
h = 0:2 · ¸ · ¸ · ¸
y(0) 1 :2
k1 = 0:2( ) = 0:2 =
·¡x(0)¸ · ¸0 ·0 ¸
0 :2 :1
k2 = 0:2f ( + 0:5 ) =0:2f ( )
· 1
¸ · ¸ 0 1:0
1:0 :2
=0:2 =
¡: 1· ¸ ¡:0 2· ¸
0 :2
k3 = 0:2f ( + 0:5 )
· 1
¸ · ¡:0 2
¸ · ¸
:1 : 99 : 198
=0:2f ( ) = 0:2 =
: 99
· ¸ · ¡: 1¸ ¡:0
·2 ¸
0 : 198 : 198
k4 = 0:2f ( + ) = 0:2f ( )
· 1¸ · ¡:0 2 ¸ : 98
:98 : 196
=0:2 =
¡: 198 ¡:0 396
Now i = 0
zi+1 = zi + 16 k1 + 13 k2 + 13 k3 + 16 k4
z1 = z0 + 16 k1 + 13 k2 + 13 k3 + 16 k4
· ¸
x
= 0 + 16 k1 + 13 k2 + 13 k3 + 16 k4
·y0 ¸ · ¸ · ¸ · ¸
0 :2 :2 : 198
= + 16 + 13 + 13 + 1

· 1¸ · 0 ¸ ¡:0 2 ¡:0 2 6

: 196 : 19867
=
¡:0 396 · : 98007 ¸ · ¸ · ¸
x(0:2) x1 : 19867
so we have ¼ =
y(0:2)
· ¸ ·y1 ¸ : 98007
z1 sin t
Exact solution is =
z2 cos t
sin(0:2) = : 19867
cos(0:2) = : 98007
1

0.5

-1 -0.5 00 0.5 1

-0.5

(sin t; cos t)
-1

This dynamic system is a point moving around a circle!


now let’s continue through next time step from t=0.2 to
t=0.4 by moving · another ¸stepsize h=0.2
y(0:2)
k1 = 0:2( )
· ¡x(0:2)
¸ · ¸
: 98007 : 19601
= 0:2 =
¡: 19867 ¡3: 9734 £ 10¡2
k2
· ¸ · ¸
: 19867 : 19601
= 0:2f ( + 0:5 ¡2 ) :
· : 98007 ¸ ¡3: 9734 £ 10
: 29668
=0:2f ( )
· : 9602 ¸ · ¸
: 9602 : 19204
=0:2 = ¡2
¡: 29668· ¸¡5: 9336· £ 10 ¸
: 19867 : 19204
k3 = 0:2f ( + 0:5 ¡2 )
· : 98007
¸ ¡5: 9336 £ 10
: 29469
=0:2f ( )
· : 9504 ¸ · ¸
: 9504 : 19008
= 0:2 = ¡2
¡: ·29469 ¸ ¡5: · 8938 £ 10 ¸
: 19867 : 19008
k4 = 0:2f ( + ¡2 ) :
· : 98007
¸ ¡5: 8938 £ 10
: 38875
0:2f ( )
· : 92113 ¸ · ¸
: 92113 : 18423
=0:2 =
¡: 38875 ¡:0 7775
Now i = 1
zi+1
· ¸ · ¸ · ¸
: 19867 : 19601 : 19204
= + 16 ¡2 + 1
3 ¡5: 9336 £ 10¡2
· : 98007 ¸ ¡3: ·9734 £ 10 ¸
1 : 19008 1 : 18423
3 ¡5: 8938 £ 10¡2
+ 6 ¡:0 7775
· ¸
: 38942
=
: 92106· ¸ · ¸ · ¸
x(0:4) x2 : 38942
so we have ¼ =
y(0:4) y2 : 92106
1

0.5

-1 -0.5 00 0.5 1

-0.5

-1

2nd point plotted, as we move around circle.

You might also like