Simnon Tutorial
Simnon Tutorial
A SIMI\ON TUTORIAL
o
A SIMT{OT{ TIJTORIAL
Karl Johan Astrm
r
l'
l1
't
Documcni ram
REPOR,T
Dte ol csuc
July
1985
Documctt Numbe
CoDEN: LUTFD2/(TFR-3176)/t-82/(1e85)
Supewsar
Author(s)
rng or;'enisa oa
A Simnon Thtorial
Abstract
The purpose of this report is to give a tutorial introduction to the simulation language SIMNON
\
t'
Key words
Clas-"ifcair syetem
,i
Srrpple.urenary
,,
bibliographicalnfomaton l t '
l.
English
ISBN
Numbe of pzgec
Recpen't n.oles
87
Seurty clssfrcton
The rcpoft m4y be odered from the Department oi automtc control o bottovcd through the Unventy Lbrary 2, Box 7070,
5-221 03 Lnnd, Sweder, Telex: 33216 tlubbis funil"
Contents
1. Introduction
A
Appendix B
Appendix C
Appendix D
Appendix E
Index 81
Appendix
79
l
, l'
,r*;
1. lntroduction
f f
n
ie vocabulary gradually.
,
Simnon
is an interactive
language
for
or difference equations. It
is
$f = r(*, .',)
Y = g(x, u)
(2.11
(2.21
.t ,i
possible to have interconnected systems where each subsystem has the form (2.1)
or
INTERACTION PRINCIPLES
to list system descriptions and data. Simnon receives information from the user
by commands from the keyboard. The commands have the forrn
CHND
argl
arg2
where CMND is the name of the command and argl, arg2, etc. are the arguments.
The name is a combination of up to eight characters. The arguments may be
identifiers or numbers. Spaces are used as separators. A command is terminated
by carriage return (CR).
Default values
It is
deslrable that commands are both short and flexible. One possibility to
achieve these conflicting goals is to allow variations of a command which are
selected by the arguments. A description of the simulation command illustrates
the idea.
The simulation command
SIHU O 1oO
,,
t
' l'
simulates a system from time 0 to time 100. If we want to repeat the simulation
second time with different parameters it suffices to write
SIHU
"4
The previous values of the afBrr6ets, i.e. O and 100, are then used. Most
commands are provided with default arguments. These arguments are then used
unless otherwise stated,
7
Time increment
Stop time
@
SIMU
T
CON
Filename
Store increment
It follows from Fig. 1 that start and stop times and the initial time increment may
be specified. It is also possible to mark curves by the optional argument MARK.
A simulation may also be continued by using the end conditions of a previous
simulation as initial values. This is done by the command option CONT. The
results of a simulation may also be stored in a file. The time spacing between the
stored values is specified by increment.
The syntax
increment> ll
t <start time> <stop time> t ((increment>
ilename>
ll
t -{coNT l}IARK}l [/<f
t
This description is called the Backus-normal form (BNF), or the Bachus-Naur
form. (...> denotes an argument i.e. a number or an identifier. [al a2...1 denotes
optional arguments which may be omitted and {al1"21...} denotes that one of the
SIHU
4,
l', ".
EXERCISES
1. Learn how to log in and log out of your computer system and how to get
access to mass storage areas. Get help from your systems manager if
necessary. Document what you are doing so that you can repeat it on your
own.
HELP.
4" Use the HELP command to find out how the command AXES works.
with the AXES command to find out how it works.
' It
tl
F;<periment
tt,
Itn
=-
3.
Differential Equations
Solution
is a simpre apprication of
simnon' In such apprications
simnon can be viewed simpty
as a carcurator for
differential equations' There
are two minor differences compared
to a calcurator.
Simnon can dispray curves.
rn a carcurator a function is
activated by pushing a
dedicated key' In simnon
functions are activated by typing
a command on the
keyboard' How sirnnon may
be used to generate sotutions
to an ordinary
differential equation is illustrated
by an example.
equations
THE PROBLEM
::i::,,tt
.2
#.^2-b)T+y=o
(3.1)
i.
2.
The
in the following
Simulate
nditions
il a satisfactory result
different steps will now be described
in some detail.
10
is
obtained. The
state x
der dx dy
dY=x
dx=a*x* (b-y*y)-y
a:1
b:1
END
Listine
1. A Simnon
as
dv
=*
(3.21
The equations are now in standard state space form, which is the format
necessary to use Simnon" A file which describes the system should now be
prepared. This file which is labeled VDPOL is listed in Listing 1. The first line
indicates that it is a continuous time system with the name VDPOL. The state
variables x and y and their derivatives dx and dy are declared. The differential
equations are then defined. Notice the strong similarity with (3.2)" Finally values
separates between @g!g!
are assigned to the parameters a and b.
-Simnon
and varia. Parameters may be assigned values in a system'description using
the notation ':' for assignment. Parlmetqrrvalues may be reassigned interactively
using the command PAR. Variables e efined using the notatiol '='.
The file can be edited using any editor you are familiar with. Assuming the
standard editor you type EDIT VDPOL,.T if you are in VMS and $EDIT VDPOL.T if
you are in Simnon. In the Vf/VlfS
system all Simnon system files have the
t /
l1 r
extension'.T'. This also appliesTto Mdcro files (Chapter 6). There is also a simple
line oriented editor built into Simnon which can be used to enter the file. This
1L
SIMULATION
To run a system
it must first
SYST VDPOL
error
message
If we would like to see the solution curves as they are integrated we must first
draw axes on the screen. This is done with the command
AXESH020V-66
which means that the ranges of the horizontal (H) and vertical (V) axes are
chosen as (0,20) and (-6,6).
The command
PLOT
' l'
'
INIT x: 1
assigns the initial value 1
,l
to
tf
th t t'atp variable
ot
!
c
c
H
!
c)
J
L
t
!
-2
a!
o
a,
.;C
-4
(,
+t
.l
+)
al,
-6
0
Timc
Figure
2.
t0
20
15
initial
SIHUO20-HARK
activates a simulation from time O to time 20, and the result shown
in Fig. 2 is
obtained. The argument -MARK implies that the curves are labeled with integers
L,2u.. in the order they appear in the plot command.
HOW TO INTERRUPT
SIMULATIOfr
' I'
CTRL-C.
13
CHANGING PARAMETERS
Suppose that
is
b:2
now generates a new simulation. Notice that it is not necessary to specify any
arguments in the command SIMU. The previously given values 0 and 20 are
automatically used as default values. The use of default values simplifies the user
interaction considerably.
continue to explore how the solution is influenced by the
parameters of the solution by a repeated use of the commands PAR and SIMU.
It is now easy to
parameters may
be
displays all
curent
state
and
DISPaxy
The display may also be directed to the line printer.
how the command DISP works is to type
simple way
to find out
HELP DISP
I'
, l'
STORING AND EDITING RESULTS OF
SIMULATION
T4
PAR
PAR
a:1
b:1
tells that the state variables x and y should be stored. The command
srHU/B1
y in a file
of
b:2
SPLIT
x/82
scaling. The
command
SHOI{
x/81
plots the variable x from file 81 in the same window. The commands
ASHoll y/82
SHorl vlBL
plots the variable y frorn files 82 and 81 the second window. To document the
results it is useful to generate a hardcopy of the curves obtined. The details
depend on the hardware. On a norrLal insNallation the command
t
, l'
HCOPY
sends a copy of the picture on thg screen to the plotter queue. The results
shown in Fig" 3 are then obtained. Th command
sPLIT 1
f,
,",
l'*
clears the screen and resets plotting to one window which covers the full screen.
t5
x
o
.;al
3!
+t
lt
{J
U'
-6.
0
Tine
10
15
20
10
15.
20
a,
It
.;c
o
o
n
+t
4J
U)
-3.
0
Timc t
Fisure
3.
for b = 1 and b = 2.
as
AXESH-44V-33
SHot{
y(x)/41
4.
+
' l'
GENERALITIES
The general way of using Simnon as a 'calculator for differential equations" will
now be given. The generic for?'{f drsystem description is given in Listing 2. Trre
system description starts with CONTINUOUS SYSTEM <Identifier>.
It is terminated
16
-1.
'l
@
.o
.;o
-2.
+t
+t
al,
-4"
-2
Statc variable
Figure 4.
Y(o) = o.
CONTINUOUS SYSTEH
for a = 1, b = 1, x(0) =
1,
<Identif ier>
differential
"GeneraI
equation
Comm en t
state <Identifier>. . .<Identifier>
der <Identifier>. . .<Identifier> Declarations
time <Identifier>
computation of auxiliary variables
computation of derivatives *
Bod
v
parameter assignment
differential
equations.
'4
,t
fi,,!'|
lt,i
where the first character mus tbea letter. Both upper and lower case letters
may be used although the compiler does not distinguish between them. The
T7
There are three types of declarations. A time variable may be declared for
simulation of time varying differential equations. This is done by the keyword
TIME followed by an dentifier. The state variables and their derivatives are
declared by the keywords STATE and DER followed by a list of the state variables
and the derivatives. associated by their sequential order in the lists.
The body of the system description specifies the derivatives of the state variables
in terms of state variables and parameters. Auxiliary variables may also be used.
The body also contains assignment of parameters and initial values. The order of
the statements in the body is unimportant. A variable may only be defined once.
Expressions and operators
The expressions available in Simnon are similar to those in a procedural language
like Algol or Pascal. An expression may be a string, a numeric constant or a
and
+-*
respectively.
Relational
operators
+
, l'
There are three relational operators, namely equal, greater than, and smaller
than. They are denoted bY
=><
Logical operators
t,
| ^, ' ',
18
Functions
(x)
absolute value
x<0
x=0
x>0
sign(x)
{l
int
x)
xrY )
X,Y
mod
max
min(x,y
sqrt (x)
exp (x)
Itr ( x)
log (*)
sin (*)
(*)
tan (*)
arcs in (")
erccos (*)
cos
atan (x)
atan2 ( x,Y)
sinh(x )
cosh (x )
tanh ( x )
arcsine
arccos
arctangent
arctangent
hyperbolic
hyperbolic
hyperbolic
SUMMARY
It has been
to
generate solutions to
ordinary differential equations in a very simple way. To do this the differential
equations are first written as a system of first order equations like
dx
Ar
= f (x,t).
, l'
I t.
is
also a special editor incorporated into Simnon, which is invoked by the command
19
The HELP command is useful in order to see what the commands do.
EXERCISES:
Learn how to use an editor on your system. Practice by editing the system
in Listing 1.
2.
Learn how to enter and exit from Simnon. Use the command LIST to list the
system you have edited on the screen and on the line printer. (Note in the
Vax implementation you may invoke a program called PRG from Sir:nnon by
typing $PRG without leaving Simnon.)
Change parameters
5.
Experiment with the commands AXES, SPLIT, SHOW, ASHOW and AREA.
6.
Use the HELP command to investigate the basic simulation commands AXES,
PLOT, INIT, PAR, SYST and SIMU.
executed. You may corect the mistak using the line editor. The simulation
is then automatically continued when you exit the editor by iyping E" You can
also leave the editor by the cqnman{ LEAVE and use your favqurite editor
forthecorrection.)
8.
,It
Use the HELP command to investigate the auxiliary commands STORE, SHOW,
DISP, ASHOW, SPLIT and AREA.
Look at the commands LIST, LP eind HCOPY and learn how to get hardcopies
of listings and plots on yout,fsYftem.
r|
h,,!
/dejr
Pbl equation
10. Consider the following van
9.
t+ (v2-t) *Y=a
20
for
( a(
1.
11. The following equations called the Volterra Lotka equations represent
simple model for the development of two competing species
dx
=(a_by)x
T=(cx-d)y
Make a Simnon program to study the equations. Start with the following
nominal values: a o 2.7,b = 0.7, c = 1 and d = 3.
d2"
dtz
la'12
ldtj
l-l=_-
& +-r
2
dt2
.2
dr d<p
dt dt =Q
where r is the radius from the center of the earth, g the azimut angle and k
a gravitational constant. Simulate the equations.
="(v-*) ,
dy
y
dt = bx - - xz,
y(o) = -a
dz
T
zl9l=24
=-cz *xy,
x(o) =-a
\
, l'
.l
tf .
Itc l',
2t
4. Difference
Equations
EXAMPLE
*k*1 = *k *. * xk * (l-xk) ,
k = 0,1,...
(4.1)
Listing3.
in
Simnon. The
(4.1) is given in
l',f'
discrete system
"Simple model
state x
new nx
time k
tsamp ts
nx=x+rr x*
POPDYII
for population
dynamics
t-*)
15=t+1
x: 0.5
r:2
END
Listins
3. A Simnon
variable in equation (4.1) changes periodically at k = !,2, .... In the general case
there may, however, be irregular sampling. The mechanism used to describe this
in Simnon is to introduce a variable TSAMP which gives the next sampling time.
In Listing 3 the first assignment statement is simply a definition of the right hand
side of the difference equation (4.1). The second line: ts=k+l assigns the value
k+l to the TSAMP variable ts. This tells that the system will be activated next at
time k+1.
SIMULATION
systems. A
syst
split
axes
plot
simu
popdyn
31
H080V01
x
0 80
X ,r
, l) t
par r:2.7O
s imu
axes
par r:2.83
t f,,
t,,
simu
23
x
c
0.75
;a
f
CL
o-
0
0
20
40.
60
80
20
40
60
80
20
40
60
80
0.75
;
a
0.75
;
f
o-
0.
Gcneration
Fisure
5.
GRAPHS OF
FUNCTIONS
.t
, l'
Simnon is conveniently used to obtain a graph of a function. Assume for example
that we want a graph of the polynomial
.ti
24
150.
f (x)
100.
50.
-50
- 100
- 150
0
-4
2
x
Fieure
x(x+3)(x+21(x-21(x-3) generated by
dx:0.05
END
The commands
th
syst pol
store f
simu -3.6 3.6
ashow
, l'
t
I
6.
"t
'f
Simnon is also convenientfy .e/tto generate level curves, field plots and
conformal maps. To illustrate such applications consider for example the problem
25
;t"jt"ot"t
G(z) =
3rr.in
the conformar
discrete system
time r
tsamp
El(pZ
fi=atfa*pi/ tg}
x=r*cos (fi )
y=r* s in (fi )
(y)
ImG=1xp(x)*siniyj
s=r*dr
dr:0.01
pi: 3. 74t5926
alfa: g0
END
The commands
syst
EXpZ
axesh-11v0l.s
plot ImG(Rec)
srmu 0 3.14
par alpha: 13S
simu 0 4.44
Z.
GENERALITIES
SYSTEM dESCriPtiON
DISCRETE SYSTEM
26
iS
USEd iNStEAd
Of CONTINUOUS
SYSTEM.
1.5
Im0
L.25
0.75
0.5
o.25
-0.5
Fisure
7.
ReG
0.5
=e.
z = r.II
and arg
z = 3rl4 in the
comment
declarations
body
END
Listins
equations
ln
l't 'I
27
for differential
, lr
lr
|','"
28
six auxiliary
commands
EXERCISES
1.
*r*r
a
= (*r +-*k
root of a. Write
2.
3.
c(t) * i(t)
+ g(t)
= Y(t-t)
i (t) = b [c(t) -.(t-1)]
c (t)
4.
x(t+l)
y(t+r)
r
x
t)
yzl
exp [-o
.t(*2 + v2)f
r
, l'
.t
f f,
29
5.
Combination
of
Systems
in Fig. 8 which is a
combination
subsystems
END
continuous system
PROC
input u
output y
I
, '
t
?
END
.t f',,
ll'l
lt
30
of
two
r
PROC
REG
Figure
8.
PROC
time t
yrIpireg] =1
yIpireg]=yIproc]
uI proc ] =uIpireg
END
Notice that states, variables, and parameters are local variables in each
subsystem. Variables in different subsystems may be specified by adding the
system name in square brackets after the identifier. Also notice that expressions
may be used to describe the interconnections. constructions like
CON
The connecting system must be the last system in the list' The order of the
systems is otherwise irrelevant. Contir,tr,'r, and discrete system may be mixed
freely.
+
, lt
AN EXAMPLE
SIMULATION OF
31
u=if
uhigh
ulow: -1
uhigh: 1
END
PROC
time t
yrIpireg]=1
yIpireg]=yIproc l
uIproc]=uIpireg l
END
Listins
5.
of a continuous
coN.
4.tf
ln
32
, t'
Action
ashow upr
Notice that the names are local to each subsystem. To distinguish between
variables that occur in different subsystem the name of the subsystem is written
in square brackets as in y[proc]. Variables can be transmitted between subsystem
by declaring them as inputs and outputs.
The results of the simulation are shown by the oscillatory curves in Fig. 9. The
discrete nature of the control actions generated by the computer are clearly
visible in the curves. These curves show that there is a considerable overshoot
due to windup at the integral. This is avoided by telling the regulator what the
process limitations are. The commands
par
par
ulow: -0.1
uhigh: 0.1
simu 0 40
area 1 I
show y yr
area 2 L
show upr
,,
GENERALITIES
9"
."t
33
T,2
la-
L
!
0"6
+t
f
e
J
o
+)
0
0
10
20.
30.
40
10
20
30
40
0.1
J
o
.;
n
L
{t
c
-0"1
0
Time
Figure
9.
systems may be simulated individually provided that no inputs and outputs are
declared. Interconnected systems may also be described by using the connecting
system. The complete syntax
B.
EXERCISES
Look at the syntax of the comnTands SIST and SIMU using the help command.
what are the differences, dtwen simulation of single systems and
interconnected systems.
has
experimentally.
f
I
34
this
3.
4.
5.
Consider the system in the example. Repeat the simulation on your own
computer. Investigate the consequences of changing the sampling period.
6.
of the different
t
, l)
f,,
35
6.
Advanced Features
Simnonmaybeusedinmanydifferentways.sofarwehavedescribedproblems
whichmaybesolvedbyusingonlyadozencommands.Thisissufficientfor
are however several
demanding problems there
more
For
applications'
many
additionalfeatures.ThesemayallbeexploredbyusingtheHELPcommandorby
readingthemanual.Abriefdescriptionofsomeusefulfeatureswillbegiven
here to indicate some possibilities'
MACROS
Commandsarenormallyreadfromtheterminal.ltis,however,usefultohave
theoptionofreadingasequenceofcommandsfromafileinstead.The
construction
HACRO NAME
Commandl
Command2
Command3
END
thusindicatesthatthecommandsl,2and3arenotexecuteddirectlybutstored
onafile.Thecommandsequenceis"thenactivatedsimplybytypingNAME"
AsanillustrationwegivettrtfoltowingmacrowhichgeneratesFis.9.
t
, l'
macro FIG9
"Generates Fig
'
36
split 2 I
ashow y/rurp
show yr y/nowup
ashow upr/wup
show upr/nowup
mark a 2.5 O
mark "Time t
markall
mark v "Control variable u
mark a t 7.5
mark v "output y and yref
END
Notice that lower case letters may be used to get a more readable code, although
Simnon does not distinguish them from upper case letters. Macros
of a dialogue.
for
for
generating
D.
for
simplification
macros. A simple macro call will then activate a whole sequence of commands.
Macros may also be used to generate new commands.
for
is strongly
recommended
it is
also possible to
facility.
INTEGRATIONALGORITHMS f
, lt
in the
ln '|
command SIMU1 lh tde algorithm the step length
is reduced until
the difference between the prediction and the correction is sufficiently small. The
tolerance may be set by the command ERROd.
37
RK
command
RKFrx I DAS}
FORTRAN SYSTEMS
The Simnon language is simple, easy to use and reliable because of all the
diagnostics that is built into it. The language has however a limited expression
power. There are no possibilities to control program flow, there are no arrays
or other data types and there are no procedures. For models whose descriptions
require a more powerful language it is possible to interface Fortran routines to
Simnon. This also makes it possible to use library subroutines like Eispac and
Linpac in the simulations. The Simnon manual describes in detail how to do this"
STANDARD SYSTEMS
There are several standard systems in Simnon. A list of the available systems is
normally displayed on the screen when.*the system is started. A few of the
systems are listed below.
DELAY
FUNCl
LOGGER
NOISEl
OPTA
IFILE
\
' '
- time delay
- nonlinearity defint Uf " t"ut"
- logging of stored variables
- white gaussian noise generator
- optimizer
- discrete system which reads output variables from
file
gaussian
38
information about the systems. The standard systems are often implemented
Fortran systems.
as
GLOBAL VARIABLES
All variables in
is conveniently done by the function FUNCI. This function has one input u
and
y. The function has one global parameter N.FUNCI which gives the
number of entries in the table. The arguments are specified by the local
parameters uit, ui?, ... . The corresponding function values are specified by the
one output
arguments gil, giZ,... . The local parameter ORDER specifies staircase (order = 0)
or linear (order = 1) interpolation.
The following dialogue illustrates how the function may be used.
Iet n.funcl = 4
syst FUNC1 FUNCPLOT
par uil: -3
par gi1: -1
par ui2: -1
par gi2: -2.8
par ui3: I
par gi3: 1.5
par ui4: 4
par gi4: 2
par order: 1
\
, l'
The global parameter n.funcl must, be assigned a value before the system is
activated by the SYST command. The local parameters may be changed by the
PAR command as parameters in f4inary Simnon systems.
,
frn
Itt
39
f (x)
2
-1
-2
-3
0
-4
2
x
Fisure 10. Graph of a function defined by a table generated using the Simnon
function FUNCI.
with
connecting system
time
FUNCPLOT
uIFUNCl]=x
yp=yIFUNCl]
END
the commands
axesh-44v-33
plot
yp
simu
-4
, '
t
I
40
There are several facilities which are useful when working with large systems or
with large amounts of data. System descriptions and macros are stored as text
files. These files have the file extension .T on the VAX/VMS system. The
subsystems also have a name which is the identifier given on the first line of the
system description. See Appendix B. Notice that the file name and the system
name may be different. This is very useful when simulating different versions of
a model because the same macros and the same connecting systems may be used.
The selection of a particular model is done when the systems are activated by the
command SYST. An illustration is given in the macro FIG9 which is listed in the
appendix. A PI regulator with the name REG is stored in a file called PIREG and a
system with the name PROC is stored in a file called INTEGR. The systems are
activated by the command
SYST INTEGR PIREG
CON
it
by
regulators.
The command SAVE stores parameters and initial values in a file. The values may
be retrieved by the command GET. These commands are very useful when
working with large models, because parameters and initial values are not
introduced manually. Assume for example,that the systems FUNC1 and FUNCPLOT
have been activated as in bcample 6.1 by the command
SYST FUNcI
FUNcPLoT ,t 1
'
The command
SAVE FUNCPAR
t',
4L
IFUNC1]
UIl: -3.
UL2: -1.
UI3: 1.
UI4:4.
GI1:
GT.2:
-1.
-2.8
GI3: 1.5
GIA:2.
order: 1.
IFUNcPLor]
DOCUMENTATION
The scale factors in the graphs are computed by an algorithm. The same axes are
obtained in horizontal or vertical direction if the horizontal range is divisible by
four and the vertical by 3. It is possible to get scale factors 1, 2 and 5 only by
the command
TURN
5125
ON
It is possible to add text to the axes by the command MARK. This is used in
the
t f,
t',
42
7.
lmplementation
When using Simnon it is helpful to have some insight into how the program
works and how it is implemented. A brief description is given in this chapter.
HOW
SIMULATION IS ORGANIZED
When the command SYST is given the equations describing the system to be
simulated are first sorted so that all calculations are done in the correct order. It
is possible to store the sorted equations in a text file by using the optional
argument [/<filename>]. The command
SYST INTEGR PIREG CON/DUHHY
INITIAL
SORTED
TIME-INDEP. EQUATIONS
cON
EQUATIONS
yr[REG] =
PROC
coN
REG
coN
PROC
Y=x
y[REc] = y[PRoC]
1+
e=yr-y
v = k*e + i , l, t
u = IF v(ulow TllEll ulow EI-SE IF v<uhigh
u[PRoc] = uIREG]
pr = IF u<-0.1 THEN -0.1 FrsE IF u<0.1
dx = upr
THEN
THEN
u EISE 0.1
ELSE
uhigh
ln
'
REG
ni=i+k*erh/ti+u-v
ts=t+h
43
The subsystem name is given to the left and the equation to the right. The
equations are sorted so that the calculations may be performed in sequential
order. The equations .are then brought to the standard form of a system of first
order differential equations, which are then integrated using the chosen
integration routine. The state variables of discrete time systems are constant
between the sampling instants. They may change discontinuously at the sampling
instants. The integration is therefore carried out only to the nearest sampling
instant. The states of the discrete systems are then changed ahd the integration is
continued.
ALGEBRAIC LOOPS
When systems are interconnected it may happen that the equations can not be
sorted so that the variables may be obtained by sequential computations. A simple
example, which illustrates what may happen is given below.
continuous system Sl
Input
Output y
V=u
END
continuous system 52
Input
Output y
V=u
END
connecting system
yr=1
uI S1 ]=y.+k*y[s2]
uI 32 I =
k
0 .5
v[sl]
END
, l'
51 52
44
'4,
i,*-In it io lize
Reod commond
Normol
Mocro
Keyboord
Doto bose
Decode commond
Commond SYST
Commond ST0P
oaa
51
c
SZ
C
51
Y=u
u[S2] = u[Sl]
Y=u
u[S1] = yr * k*y[S2]
Y=u
The variable u[Sl] thus can not be solved sequentially. A simple calculation
shows that the variable is given by the following algebraic equation:
u[S1]=]F*k*u[Sl]
This explains the name algebraic loop. In this particular case it is easy to solve
the equation if k # 1. In the general case the algebraic equation may be nonlinear.
It is then difficult both to determine if a solution exist and to find it if it does.
Simnon will not attempt to find a solution. It will just give an eror message. The
presence of an algebraic loop is often an indication of poor modeling. Models with
algebraic loops may be integrated with the qroutine DAS.
t
, l'
for
Simnon
45
Simnon is given
in ApPendix
E.
t
, l'
t',
46
,n
code.
8.
References
control systems.
See
,strm, K J (1983):
Computer aided modeling, analysis and design of control systems
perspective. Control Systems Magazine, May, pp 4-16.
Simnon inherited many ideas from the tradition of analog and digital simulation in
the control engineering field. When the work on Simnon was started there were
a number of digital simulation languages like CSSL and CSMP available. These are
described in the book
Korn, G" A. (1978):
Digital Continuous Systern Simulation. Prentice Hall. Englewood Cliffs,
New Jersey
which contains much useful information on simulation. Languages like CSMP and
CSSL were, however, implemented using batch calculations. Since the languages
largely were inspired by analog simulation techniques they also inherited several
constraints imposed by the analog hardware. For example the state space notation
which is so natural was not supported 6y p.op"r language constructs. When
Simnon was developed the main ida was, to provide a tool which stpports the
state space notation with good,rnBh-rffachine interaction based on interactive
computing.
Elmqvist, H (1975):
SIMNON, an interactive simulation pfogra
for nonlinear
systems.
47
generated
by Simnon
Macros
which are accessible to the students. They can then easily change parameters and
modify graphs.
and
Wieslander, J (1979):
Interaction in computer aided analysis and design of control systems.
PhD thesis, Report TFRT-1019, Dept of Automatic Control, Lund
Institute of Technology, Lund, Sweden.
and
Wieslander, J (1980a):
'l
The program Intrac, which is the core of the interaction with the user,
described in
Wieslander, J and ElmqvisUfH 11978):
INTRAC, A communicatiorf pddrle for interactive programs. Language
manual. Report TFRT-3149, Dept of Automatic Control, Lund Institute
of Technology, Lund, Sweden.
48
is
APPENDIX A
A list of the commands, their syntax and brief descriptions are given below.
Some Intrac commands (denoted bV t) are also included in the list. More details
about the commands are obtained using the command HELP.
All Intrac
implementations
commands
on
VAX-11
{op1
1... loptt}
t....1
}*
be
omitted.
Defines arguments
, l,
l^,
f,
49
ALGOR
RKFIX
DAS
AREA
2
3
Column
Row
Var
ASHOW
Lt
50
sr
MARK
Varidble
Stop
Filename
Max volue
Max value
TP
LP
FF
LF
teleprinter
line Printer
form feed (default when no variables are specified)
line feed (default when variables are specified)
If no variables are given all variables are displayed.
DIS
FF
rP
LF
Variable
LP
DISP
I
l'
t',
f,
51
EDIT <filename>
To edit a file. The editor has two modes, INPUT and EDIT. The mode is
changed by entering an empty line. In the edit mode it is possible to change
the current file. The following commands are available:
Append string to current line
AIPPEND] <string>
Line pointer to bottom
Blorrl
Replace string x by string y
clHANGl l"lvl
Delete n lines
D[EL] <integer>
Drs [oNloFF]
EIxrr]
F[lND] <string>
I[NS] <string>
L[OC] <string>
LEAVE
N[EXT] <integer>
OIVERL] <integer>
PIRINT] <integer>
RIETYP] <string>
rloPl
EDTT
ERROR
File name
<error bound>
To choose
ERROR
eror
bound
Error bound
GET <filename>
To get parameter values and initial values from a file that previously
been stored using SAVE
GET
or
edited.
File name
, l)
i
|'
52
.,t
'
'.
has
<swlTcH>]
rsHow)
is scaled with
on display' The hardcoPY
Make a hardcopy of curves interval
(0.5, 1.6) The cmment is obtained
<factor), *nillil"v be in the
on the hardcoPY too'
= 1b
Factor
HCOPY
ON
OFF
sH0w
, l,
t f,,
53
HELP
To get more information about the commands, the editor, Intrac, Simnon, and
the standard systems. A menu of commands is obtained by typing HELP.
Nslosk
Dts
LF
ASK
FF
fP
o
HEL
Detail of simnon
Intrac command
Simnon command
INTRAC
SYSTEM
I
INIT
.Number
State voriable
Varioble
i
54
/,,
@
LET
for
the
Number
Variab le
Number
nlege
ldent if ier
Delimiter
Unassigned varioble
Dts
LF
rP
FF
LP
Filename
Ltsr
55
LP
or
commands
PRINT.
MARK
To introduce text into a plot. For syntax type HELP INTRAC MARK.
MARK
NEWS
PAR <parameter>
: {<number>lcvariable>}
Porameter
Var
[ {<variable>} *
ia ble
[(<variable>)] l
To select variables to be plott when making the command SIMU:
Examples: PLOT XL X2 give5 Xl nd X2 as functions of time while PLOT
X1(X2) gives Xl as function of X2.
PLOT
Vorioble
Varable
PLOT
56
[/<start time>]
To list file generated with the commands STORE+SIMU. <lines> lines starting
from (start time> will be printed. The other parameters are the same as for
DISP.
Dts
LF
TP
FF
LP
@
F
ilenome
Stort time
Lines
system
GET'
command
the
by
used
be
<filename>
to
<systemname> on a file named
INIT.
or
PAR
option
the
with
are
saved
only parameters or initial values
PAR
lr
Filenome
\
, t'
t
l*,
f,"
57
To plot stored variables from file <filename>. To be used with the command
STORE. The specified variables are plotted frorn <start> to <stop> time. If
MARK is used the different variables are numbered on the plot. The
LlST-option lists the names of all variables.
Voriable
Stop
@
Variable
@
LI
ST
Filename
MARK
@
@
\
l'
hI
58
t,
Stort time
Stop time
SIMU
CONT
coNr
Filename
Store increment
Row
Column
tl
f.r
^,r
59
A special command, which is only used with the integration routine DAS.
FAST
Varid ble
Voridble
Time increment
STATUS
STOP I
To leave Simnon.
sfoP
,l
STORE
I (,.t
l',
60
EXEC -
LOG TRACE -
Default OFF.
Executed commands are logged on line printer. Default OFF
Affects ECHO and LOG.
CLOCK
DATE
ON
ECHO
SWITCH
EXEC
OFF
LOG
TRACE
To define the system. The subsystems are compiled. If there are several
subsystems the last one has to be a connecting system. EDIT means that the
compiler goes into the editor for each file. If filename is specified the sorted
equations are written into a text file.
ED
EXIT
SYST
I d ent
ilename
if ier
TEXT
ln,
61
DARK
DIS
lnforms
between
calculations. Default
OFF"
DARK
Dt5
ON
rURN
OVFLO
OFF
PLCOM
s 125
TIMING
t
, l'
l^,
62
f,,
I
I
the
APPENDIX B
{
*
exclusive or
optional element
compulsory element
repetition
<Ietter>:: =AlB c
alb c
<digit>::=
F G H I J
o
j
d e
h
011 2 3 4 5 6 7 8
D E
IDENTIFIERS
<identifier><digit>,F
1h
VARIABLES
, ,t
<system
't
'
identifier>]
t.t (
l',
63
CONTINUOUS
fturrtrl
ls8il"."tton
t Computation of auxiliary variables]
t Computation of output variables]
t Computation of derivatives]
Parameter assignment
IInitial value assignment]
END
DISCRETE SYSTEH
<system
identifier>
instant
tl r
64
CONNECTING SYSTET{
<system
identifier>
END
Note that the order of the computations and assignment is unimportant because
the equations will be sorted automatically. The section Initial makes it possible to
compute initial values to state outputs and TSAMP. These variables can normally
not be assigned an expression.
It
r',
65
APPENDIX
Standard Systems
This appendix describes the standard systems DELAY, FUNCI, IFILE, LOGGER,
NOISEI, OPTA, and STIME. These systems are written in Fortran and linked into
Simnon.
DELAY
This discrete time system simulates pure time delays. Old values of the signal to
be delayed are stored in a vector. Delayed values are then generated by
interpolation. The system admits two interpolation schemes due to Hermite and
Aitken. In Aitken's scheme a Lagrange polynomial is fitted to the stored values. In
Herrnites method the values of the derivatives are stored together with the
function values. The delayed values are then determined using an interpolation
polynomial, which agrees with the function and its derivative at the stored points.
Hermite's method requires that derivatives of the function are also stored.
The function admits delay of many signals. It has the following global variables.
nl.delay
n2.delay
space.delay
66
t^r
u1,u2,...
du1du2,..
td1,td2,...
OUTPUT:
yL,y2...
for
example
continuous system
SYSI
END
connecting system
time t
td1[detaY]=t-5
u1
CONN
[de I aY]=s in ( t )
let nl.delay=g
Iet n2.delay=1
Iet space.delay={5g
The systems are activated by the command
u[sys1] (t)
lt
I
=
ift<5
sin(t-5)
,r'^
ift>5
67
FUNCl
funct
which gives the number of tabulated function values. The local variables are:
INPUT:
Argument value
u
OUTPUT:
Function value
v
PAR:
order
or 1)
continuous system
SYS1
END
connecting system
time t
u t func 1 ]=
u t sys 1 ]=yI func I
CONN
END
let n.funcl=S
The systems are activated by the
"o.*"nif
,
, t' '
The parameters of the system FUNCI are defined by the commands
68
rt
par
par
par
par
par
par
par
par
par
par
par
ui1:0
gil:0
ui2: 1
gi2: I
ui3: 2
gi3: 4
ui4: 3
gi4: 9
ui5: 4
gi5:16
order: 1
"Use
linear interpolation
The parameters of the system FUNC1 are saved on file TAB1.T by the command
save
tabl funcl
IFILE
n.ifile
fname"ifile
c2
PAR:
dt 1
dt
TSAMP:
ts
Time
The actual value of n.ifile is fixed during the execution of the SYST command. The
.'
value of fname.ifile can be charlged
't 'r etween simulations. The simulation terminates
if the input file is exhausted.
.t
69
continuous system
SYS1
END
connecting system
time t
u[sYs1]=s3[ifile]
CONN
END
The global variables of the system IFILE are assigned by the comrnand
let
Iet
n. ifile=10
fname. ifile=fdat
conn
The file used as input to IFILE can be created in Sirnnon using a store command.
It can also be generated in the system identification package ldpac.
LOGGER
,F
"".t"
arbitrary
file.npoint
which gives the number of dat{ qoints stored in the current STORE file with
Jt; t '
by LOGGER after each simulation. It can be
name <file>. The global variableT is set
displayed by the WRITE command. (This value rnust be known if the generated file
70
is to be used by ldpac.)
The local variables are:
PAR:
dt1
dt
TSAMP:
ts
Time
a system
continuous system
SYS1
SYS1
END
connecting system
time t
CONN
END
conn
par dt[Iogger]:10
par dt1[loggerf:2
The command request the variabp x of SYS1 to be stored.
store x[sys1]
t',
The following simulation command executes the simulation with the option that the
71
simuO1500/fifl
Notice that the number
variable
write fill.npoint
149
NOISEl
n.noisel
nodd.noisel
stdevl, stedv2,
Standard deviations
1.0)
dtl
Time
dt
same
rect
TSAMP
ts
0.0)
Time
g-
and
g!
72
Example. Generate two white noise input signals to the system SYSI. The signals
should start at
continuous system
SYSI
END
connecting system
CONN
time t
u1 t sys 1 l =e1 t noisel l
u2 t sys 1 l =e2 t noisel l
END
The global variables of the system NOISE1 are assigned by the commands
let n.noisel=2
Iet nodd.noisel=25831
The systems are activated by the command
conn
par dt:3
Iet dt1: 0. 5
STIME
This system stores clocktime and cpu-ti."'r, the two Simnon variables MSCLOCK
and MSCPU. lt is useful for tlming rof simulations and for investigating
computational efficiency. No conrr""/ig !yrt"* is needed. It is sufficient to include
STIME in the SYST command" The variables MSCLOCK and MSCPU are set to zero
at the start of each simulation.
I
I
73
OPTA
J(p)
st(n) f o
i = 1, ...,
lrl.
The system OPTA performs the minimization recursively. The system has old
values of the parameters as states. It accepts values of J and g as inputs and it
generates new values of the parameters, which will give a smaller loss function
as outputs.
npar.opta
ncons.opta
loss
con1,con2
OUTPUT:
pr,p2
tbeg
PAR:
Sampling period
tinc
parameters,
...
(-0.5) Controls initial st+ at thB first linear minimization; ,should give
an estimate of the likely edtrction in function value, Af; there are two
possibilities:
DFN<O DFN itself is an estimate of Af
DFN<O ABS(DFN).f is taken as an estimate
TINC
HH
EPS
74
EPS
of Af
for
unc,onstrained minimization
- is
satisfied
EVMAX
CEQ
DELTA
constrained
when
TEST
RESET
DARK
if RESET>O
MODE
second
derivative, H
MODE=I
MODE=3
LPLOT
is
Glad
(1e74).
The system OPTA can be used in many different ways. Typical applications are to
\,
System
0ptimizer
Figure C-l
the optimizer it uses the current values of J and I to compute the next value of
p. If the criterion or constraints depend explicitly on the parameter vector p, a
vector pd, containing delayed values of p, is used. The system can consist of a
nurnber of subsystems. The connections between these subsystems, as well as
connections needed to forrn J and g frorn output of the subsysterns, are made in
the connecting sYstem.
used.
J= I
2
2
dr
s=[0
<
dt - u-.
llm - 0
T)
u-.
Ilm = 0.5
The gains KO and KO should be chosen to satisfy these demands. The Simnon
prograrns required to solve the problem are given below.
.tl
76
x1
Figure C-2
continuous system
state xl x2 z w
der dxl dx2 dz dw
input kd kp
IHP
output y
output y=1!
Y=x2
dlmamics
u=-kd*x1-kp*x2
dx1=-x1+u
dx2=xl
dz=u*u
dw=x2*x2
END
connecting system
time tim
wt: 1O
I oss
CONN
ulim: .5
lt
, l,
t=tim-tbeg[opta]
END
,,
To do the optirnization the sloaf (rariables of OPTA are first assigned by the
commands
77
let npar.opta=2
Iet ncons.opta=l
The systems are then activated by the command
conn
init xl: 1
init pil:2
nt pi2:2
The sampling period of the system OPTA is set by the command
par tinc:10
The command
par prin:5
tells that parameters, function values and gradients are printed. The optimization
is then executed by
.5
l'
4t
t','
78
APPENDIX D
for
F9"
split 1 1
axesh020v-66
plot x y
store x y
init x: I
simu 0 20 -mark/bl
mark a 2.5 O
t
markall
mark v "State variables x
mark "Time
and
marked
and 2
END
state x
der dx dy
dY=x
dx=a*x* (b-y*y)
a:1
b:1
-y
END
l'
macro FIG3
syst vdpol
init x: L
store x y
simu 0 2lb7
par b:2
s
imu/ b2
split 2 I
axesh020v-66
show x /b1
79
show x
axes v
show v
show Y
lb2
-33
lbt
lb2
mark a 2.5 0
mark tl.T. lme t
markall
mark v "State variable
mark a L 7.5
mark v "State variable
y
x
END
macro FIG4
"Phase plane
syst vdpol
init x: 1
split 1 1
axesh-44v-33
plot y(x)
simu 0 20
mark a 2.5 O
mark 'oState variable x
markall
mark v "State variable
END
macro FIGS
syst
20
popdyn
split 3 1
axesh080v01
par r:0.2
plot x
simu 0 80
mark a 2.5 O
mark "Generation k
markall
mark v "Population
nark a I 5.5
mark v "Population
mark a110
mark v "Population
x
x
\,
, lt
axes
par r:2.7O
simu
axes
par r:2.83
s
imu
END
80
rr,
''
discrete system
POPDIN
r:2
END
macro FIG6
syst POL
store f
simu -3.6 3.6
split 1 1
ashow f
mark a 17 0
mark ttx
mark a O.5 12
mark "f(x)
END
macro FIGZ
"Generates
syst
Fig.
EXPZ
split 1 1
axesh-11v01.5
plot ImG (ReC)
simu 0 3.14
par alfa:135
simu 0 4.44
mark a 17 0
mark "Re G
mark a O.5
mark "Im G
1t
It
72
END
f
I
fi=alfa*pi/ 180
x=r* cos (fi )
81
(f i)
ReG=exp (x )*" os (v)
ImG=exp (x )*t in (v)
y=r* s in
5=*dr^
dr:0.01
pi:3.
t'4L5926
alfa:
90
END
macro FIGO
"Generates
Fig.
split 2
ashow Y/vruP
show Yr Y/nowuP
ashow uPr/wuP
show uPr/nowup
mark a 2"5 O
mark "Time t
markall
*u.f. "Control variable u
mark "a 7 7-5
rurf " "OutPut Y and Yref
END
continuous sYstem
;;;;;;;;;o'
PROC
*itt' inPut
saturation
input u
output Y
state x
ffii=i
if
dx=upr
V=x
END
, t'
discrete
sYstem PIREG
input Yr
output u
.,f
t
l'" '
tsamP ts
e=yr-y
9=l s+i
u=if vculow then ulow else
82
uhigh
ti:
h: 0.5
ulow: -1
uhigh:
END
PROC
time t
YrIpireg]=1
y[Rireg ] =yIproc
uIproc ] =uIpi reg
]
]
END
macro FIG10
let n.funcl=
10
axesh-44v-33
plot yp
simu -4 4
mark a 17 0
mark ttx
mark a I 12
mark "f (x)
END
connecting system
FUNCPLOT
time
x
u[FUNCl ]=x
yp=yIFUNCt]
END
IFUNC1]
UI1: -3.
UIZ: -L.
UI3: 1.
\
l,
't
UI4:4.
GI1:-1.
GI2: -2.8
GI3: 1.5
Gl(:2.
order: 1.
IFUNCPLoT]
83
APPENDIX
WRITE
SWITCH
STOP
2. Assignment
FREE
LET
Loop
4. Macro
DEFAULT
MACRO
FORMAL
END
SUSPEND
RESUME
SIMNON COMMANDS
EDIT
DISP
84
GET
LIST
PRINT
SAVE
STOP
2. Graphic output
AREA
ASHOW
AXES
HCOPY
MARK
SHOW
SPLIT
TEXT
3. Simulation
ALGOR
ERROR
INIT
PAR
PLOT
SIMU
STATE
STORE
SYST
4. Auxiliary
\
It
,rr^
85
lrdex
advanced features, 36
algebraic loop, 45
aigebraic loops, 44
ALGOR, 38, 49, 85
AREA, 20,29,50, g5
arithmetic operators, 18
ASHOW,50, g5
AXES, 72,20, 28, 51., 85
Backus-normal form, I
BNF, 8
changing parameters, 14
combination of systems, 30
command, 7
command syntax, 8, 49
cornputer control, 3i
coN,
83
conformal maps, 25
connecting system, 7, 33, 65
connecting system., 30
continuous system, 6, 30, 33, 64
CSMP, 47
CSSL, 47
DAS, 38, 45
DEFAULT, 84
default values, 7
DELAY, 38, 66
DER, 18
difference equations, 22
differential equations, 10
discrete system, 6, 26,30, 33, 64 * tt
,
DISP, 14,20,29, 51, g4
documentation, 42
EDIT, T2, T9,51, 84
edit mode, 11
edit mode: how to leave it, 12
END, 84
"4 ,f
ERROR, 37,52, 85
r
| ''
experimental data, 69
experimental data in simulations, 69
expression power, 38
expressions, 18
86
EXPZ, 81
field plots, 25
FIGIO, 83
FlGz,79
FIG3, 79
FIG4, BO
FIGs, BO
FIG6, 81
FIG7, 81
FiGg, 36, 82
file, 69
FOR..TO, 84
FORMAL,84
Fortran, 38
Fortran systems,
38
FREE, 84
FUNCI,38,39, 41,66,68
FUNCPLOT, 41, 83
functions, 19
functions in tabular form, 68
GET, 41, 52,85
global parameter, 39
global variables, 39
GOTO L, 84
graphs of functions, 24
HAMPC,38
hardcopy,
15
HCOPY, 15,20,28,52,95
HELP, 20, 53, 85
IDENTIFIERS, 63
IF..GOTO, 84
IFILE, 38, 66, 69
INIT, 12, 20,29,54, g5
integration algorithms, 37
interaction principles, 7
Intrac, 45
LABEL L, 84
large simulations,
LEAVE, 12
LET, 54, 84
LET,TERS, 63
41
level curves,25
LIST, 12, 19, 55, g5
local parameter, 39
local variables, 33, 39
LOGGER, 38, 66, 70
logical operators, 18
sToRE, 15,20,29,60,95
store parameters, 41
subsystem, 30
SUSPEND, 84
SWITCH, 42,60,84
syntax, 8, 49
syntax diagnam, 7
SYST, 72,20,29, 37,61, g5
system description, 10, 64
table nonlinearities, 38
TEXT, 61, g5
TIME, 18
time delay, 66
timing of simulations, 73
37
LP, 56
MACRO, 36,94
macros, 36
Macros for generating the figures, 79
MARK, 42,56,85
minimization, T4
NEWS, 56, 85
NEXT V, 84
TSAMP,23
TURN, 42,6I,85
upper case letters, 16
van der Pol equation, 10
variables, 11, 63
variables local, 33
variables transmission to other systems, 33
VDPOL, 79
vector notation, 19, 38
WRITE,84
[FUNCl], 83
NOISE, 38
'IOISEI, 66,72
numeric integration, 37
operators, 18
oPTA, 39,66,74
optimization, TS
PAR, 11, 14,20,28, 56, g5
parameter adjustment, 75
parameters, 11
phase plane plots, 16
Pl regulator,32
PLOT, 12,20,29, 56, 85
POL, 81
POPDYN, 80
population dynamics, 22
PRINT, 56, 85
FROC, g2
READ, 84
REG, 82
relational operators,
18
RESUME, 84
retrieve parameters,
41
RK, 38
RKFIX, 38
SAVE, 41,57,85
scale factors, 42
sHow, 20,29,57,85
Simnon commands, 84
Simnon language, 38
slMU, 7, 72, 20, 29, 59, g5
simulation, 12.
simulation command, 7
sorting, 43
source code,46
SPLIT, 20,2g,5g, g5
standard systems, use of,
STATE, 18,59,85
STIME, 66, 73
sToP, 60, 94, g5
|
, I'
,t
."4 f
39 | ',
87