
1-9. Sorting Defined-variable Assignments
DYNAMIC-segment operations (1-1) preceding an
OUT or SAMPLE m state-
ment (if any) execute at every derivative call of the differential-equation-solv-
ing integration routine. Each derivative or defined-variable assignment uses the
value of
t and the values of the state variables xi computed by the last deriva-
tive call. Derivative and defined-variable values for
t = t0 are derived from the
initial state-variable values and
t0 by an extra initial derivative call.
The defined-variable assignments (1-1b) must execute in the correct pro-
cedural order to derive each
yj value from the state-variable values and t, pos-
sibly using already computed
yi values. An out-of-order assignment would
incorrectly try to use defined-variable values from an earlier derivative call.
The state equations (1-1a) are normally programmed following the defined-
variable assignments (1-1b).
Conventional simulation programs such as ACSL
©
automatically sort the
defined-variable assignments so that they use only
yi values already com-
puted during the current derivative call. If that is impossible due to an “alge-
braic loop,” the program returns an error message (sort error). DESIRE’s
more general program system does not sort statements automatically. But in
programs without subscripted variables or vectors (Chapter 3), DESIRE pre-
vents assignments to undefined variables, and thus algebraic loops, by return-
ing an error message (see also Section 3-5).
3
EXAMPLES OF SIMPLE APPLICATIONS
1-10. Oscillators and Computer Displays
(a) A Linear Harmonic Oscillator
The complete small program in Figure 1-3 illustrates the main features of a
DESIRE simulation. The DYNAMIC program segment following the
DYNAMIC statement in Figure 1-3a defines our model. We have modeled a
simple damped harmonic oscillator or mass–spring–dashpot system with the
differential equations
d/dt x = xdot | d/dt xdot = – ww * x – r * xdot
12
Introduction to Dynamic-system Simulation
3
Recursive assignments that input the assigned-to variable on the right-hand side, as in
y = y + x y = a * x1 + y * x2
do not ordinarily appear in differential-equation code. If they do, DESIRE does not flag them
with error messages but considers them as difference equations and assigns
y the initial value 0
(Sections 2-1 and 2-2).