Page 51 - DCAP601_SIMULATION_AND_MODELING
P. 51
Unit 3: Simulation of Continuous System (II)
An instantaneous description of the state of the system is given by the outputs of the two Notes
integrators, i.e., by variables y and y . We will use, once again, the fourth-order Runge-Kutta
l 2
method to obtain the values of y and y as a function of time. We will choose the step-size
1 2
t = H = .001 second and simulate the system for 5 seconds. Thus the number of steps will be
N = 5,000. This is too large a number of outputs to be plotted or examined. We will, therefore,
print out the values of y and y only once every 100 integration steps. This can be implemented
1 2
by keeping a counter K which is decremented by I for each integration step. Every time K equals
zero, y and y are printed and K is reset to 100. The following FORTRAN program performs the
1 2
simulation.
C H IS TIME STEP, N IS NO. OF STEPS, Yl, Y2 INITIAL VALUES
T = O.
YI = 1.
Y2 = 0.
H = .001
N = 5000
K= 1
DO 120 I – I, N
K = K – I
IF (K.NE.O) GO TO 110
C PRINT ONCE IN 100 STEPS
PRINT, T, YI, Y2
K = 100
C CALCULATE THE RUNGE-KUTTA TERMS
110 Ull = H*Y2
UI2 = H*(.1*(1. – Y1*Y1)*Y2 – Y1)
U21 = H*(Y2*+ .5*UI2)
U22 = H*(.1 *(l. – (YI +.5*U11)*(Y1 +.5*U11)*(Y2+.5*U12) – (Y1 +.5*U11)
U31 = H*(Y2 + .5*U22)
U32 = H*(.1 *(1. – (Y1 +.5*U2l)*(Y1 + .5*U21))*(Y2+ .5*U22) – (Y1 + .5*U21)
U41 = H*(Y2 + U32)
U42 = H*(.I*(1. – (Y1 + U31)*(Y1 + U3l)*(Y2 + U32) – (Yl + U31)
C CALCULATE Y1 AND Y2
Yl = Y1 + (U11 + 2.*U21 + 2.*U31 + U4l)/6.
Y2 = Y2 + (U12 + 2.*U22 + 2.*U32 + U42)/6.
T = T + H
120 CONTINUE
PRINT, T, YI, Y2
STOP
END
By studying the three examples in this unit so far, you may have acquired the incorrect impression
that (i) every dynamic continuous system must first be expressed as a set of simultaneous
differential equations before being simulated and, that (ii) such a system is always deterministic.
The next example is meant precisely to dispel this notion. Moreover, in this example we are
simulating a system which is too large and expensive to ex· periment with and where an
incorrect design could become very costly.
LOVELY PROFESSIONAL UNIVERSITY 45