130 4 Dynamical Behaviour of Processes
The programs for implementation of the fourth order Runge-Kutta method
in various computer languages are given in the next example.
Example 4.6: Programs for the solution of state-space equations
www
We will explain the use of the fourth order Runge-Kutta method applied
to the following second order differential equation
T
1
T
2
d
2
y
2
dt
2
+(T
1
+ T
2
)
dy
2
dt
+ y
2
= Z
1
u
with zero initial conditions and for u(t)=1(t). T
1
,T
2
are time constants
and Z
1
gain of this system. At first we transform this differential equation
into state-space so that two differential equations of the first order result
dx
1
dt
=
Z
1
u −x
2
− (T
1
+ T
2
)x
1
T
1
T
2
dx
2
dt
= x
1
The program written in GW-BASIC is given in Program 4.1. The state-
space differential equations are defined on lines 550, 560. The solution y
1
(t)=
x
1
(t), y
2
(t)=x
2
(t) calculated with this program is given in Table 4.1. The
values of variable y
2
(t) represent the step response of the system with transfer
function
G(s)=
Y (s)
U(s)
=
Z
1
(T
1
s + 1)(T
2
s +1)
Program 4.2 is written in C. The example of the solution in the simula-
tion environment MATLAB/Simulink is given in Program 4.3. This represents
m-file that can be introduced as S-function into Simulink block scheme shown
in Fig. 4.9. The graphical solution is then shown in Fig. 4.10 and it is the same
as in Tab. 4.1.
Program 4.1 (Simulation program in GW-BASIC)
5 REM ruku4.bas
10 REM solution of the ODE system
20 REM n number of equations
30 REM h integration step
50 REM y(1),y(2),...,y(n) initial conditions
55 DATA 2: READ n
58 DIM y(n), x(n), f(n), k(4, n)
60 DATA .5, 0, 0
70 READ h
80 FOR i = 1 TO n: READ y(i): NEXT i
140 PRINT "t", "y1", "y2"
160 PRINT t, y(1), y(2)
200 FOR k = 0 TO 19
205 FORi=1TOn:x(i) = y(i): NEXT i: GOSUB 470