LUND UNIVERSITY PO Box 117 221 00 Lund
A Simnon Tutorial
Åström, Karl Johan
1985
Document Version:
Publisher's PDF, also known as Version of record Link to publication
Citation for published version (APA):
Åström, K. J. (1985). A Simnon Tutorial. (Research Reports TFRT-3176). Department of Automatic Control, Lund Institute of Technology (LTH).
Total number of authors:
1
General rights
Unless other specific re-use rights are stated the following general rights apply:
Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights.
• Users may download and print one copy of any publication from the public portal for the purpose of private study or research.
• You may not further distribute the material or use it for any profit-making activity or commercial gain • You may freely distribute the URL identifying the publication in the public portal
Read more about Creative commons licenses: https://creativecommons.org/licenses/
Take down policy
If you believe that this document breaches copyright please contact us providing details, and we will remove access to the work immediately and investigate your claim.
coDEN: LUTFD2/(TFRT-3176) I
r-87I Fe85)
A SIMI\ON TUTORIAL
Karl Johan Aström
oï
bI ?
,,|úr}urtment of Automatic Control Lund Institute of Technology
July
A SIMT{OT{ TIJTORIAL
Karl Johan Aström
r
l' t
Department of Automatic Control Lund Ins+içute of Technology
l1 t 't lt¡
Revised edition, July 1985
Department of Automatic Control Lund Institute of lechnology
P.O. Box 118
5-227 00
Lund
SwedenDocumcni ramë
REPOR,T
D¿te ol ícsuc
July 1985
CoDEN: LUTFD2/(TFRÎ-3176)/t-82/(1e85)
Documctt Numbe¡
SupewÍsar Author(s)
Karl Johan Å,"ttõ-
S p o ns o rín g or;'enisa úíoa
Title and subtitle
A Simnon Thtorial
Abstract
The purpose of this report is to give a tutorial introduction to the simulation language SIMNON
Key words ¡
i
\ t'
Clas-"ifcaúiø¡r syetem aad/or inilex tcrms (i¡ q)
,i
,,Srrpple.urenúary bibliographicalínfo¡matíon l¡ t ' l.
ISSN and hey tìtle ISBN
Languagc
English
Numbe¡ of pzgec 87
Seurìty cl¿ssífrc¿tìon
RecípÍenú't n.oles
Contents
1.
Introduction
52. T}re Conceptual
Framework
63. Differential
Equations
104. Difference Equations 22
5. Combination of
Systems
296. Advanced
Features
357. Implementation 42
8. References 45
Appendix
A -
Syntaxfor
Simnon Commands 47 AppendixB -
Syntax of System Descriptions 59 AppendixC -
Standard Systems 61Appendix
D -
Intrac and Simnon Commands 74 AppendixE -
Macrosfor
Generating theFigures
79Index
81l
, l'
I,r*;
f
1. lntroduction
Simnon
is a
special programming languagefor
simulating dynamical systems.Systems
may be
describedas ordinary
differential equations,as
difference equationor
as combinationsof
such equations. Modelsof
this type are commonin
mathematics, biology, economics andin
many branchesof
engineering. Simnonrequires
a
computerwith a
graphics terminal. The resultsare
displayed as curveson the
terminal. The language hasan
interactive implementation which makesit
easyfor
a user to work with the system. Simnon may be used in a very simple way to find solutions to differenceor
differential equations. This requires only six commands. There are 38 additional commandsin
the system. They also allow optimization, introduction of experimental data and parameter fitting"The purpose
of this report is to
providean
introductionto the
simulation language. The conceptual frameworkis first
describedin
Chapter2.
Thre report then proceeds by examples. Chapter 3 describes howto
solve simple differential equations. Solutionof
difference equationsis
describedin
Chapter4.
Chapter 5 describes simulationof more
complicated systemswhich are
obtained by combining subsystems describedby
differentialor
difference equations.It
isuseful
to
note thatall of
this can be accomplishedby
about a dozen commands.Some advanced features
are
describedin
Chapter6. A few
remarkson
the implementation are givenin
Chapter7.
Eæh chapteris
providedwith
exercises.Do
not
forgetto
experiment and testat a
terminal asyou prog."r, with
thereading. Remember
that you
""r,
l.¡*"ys'
type HELP andthat there is
also a manualwhich
givesa
detailed description tof the
language constructs. Also remember that a good wayto
learn the languageis to
startby
learning how to master a few commands and expanai¡e
vocabulary gradually.f¡
l1 n f ,
2. The Conceptual Framework
Simnon
is
an interactive languagefor
simulating dynamical systems. The system may be described by ordinary differential equations,or
difference equations.It
isalso possible
to
simulate systems which consistof
interconnected subsystems.This is useful in order to structure a large system. Simnon may also be used for other purposes e.g. to graph functions to
fit
models to data etc.The simulation language has facilities
to edit
system descriptions,to
integrate differential equations, to store and retrieve data, to show the solutions as graphs, and to change parameters and initial conditions.DESCRIPTIONS OF DYNAMICAL SYSTEMS
To
use Simnonit is
necessaryto
havea
basic understandingof
dynamicalsystems.
In
particularto
be familiarwith
the notionsof
input, output and state.The generic form of a continuous time system is
$f = r(*,
.',)Y = g(x,
u)(2.11
where
u
is a vector of inputs,y
a vector of outputs andx
is the state vector. A system like (2.1) is specified as a CONTIITIUOUS SYSTEMin
Simnon. The analogousform
for
a discrete time systemis
I*(.r*r) = r(x(t¡), u(t¡)),
v(tr) =s(x(tt) ,u(t¡))., k-1,2,..
(2.21A
system like (2.21is specified/.t
,ias a'ÐISCRETE SYSTEM. Simnon allows
a
systemor
a subsystemto
be describedby
eitherof
the forms (2.1)or
(2.2).lt is
alsopossible to have interconnected systems where each subsystem has the form (2.1)
or
(2.21. Connections are described as a CONNECTING SYSTEM.INTERACTION PRINCIPLES
Simnon gives information
to
the uservia a
graphical screen which can showcurves, text and numbers.
It
is also possible to get a hard copy of a picture andto list
system descriptions and data. Simnon receives information from the user by commands from the keyboard. The commands have the forrnCHND
argl
arg2where CMND is the name of the command and
argl,
arg2, etc. are the arguments.The name
is a
combinationof up to
eight characters. The arguments may be identifiersor
numbers. Spaces are used as separators.A
command is terminated by carriagereturn
(CR).Default values
It is
deslrablethat
commandsare
bothshort
and flexible. One possibility to achieve these conflicting goalsis to
allow variationsof a
command which are selectedby
the arguments.A
descriptionof
the simulation command illustrates the idea.The simulation command
The different
forms of the
command SIMU which executesa
simulationof
asystem are illustrated
in
the syntax diagram Fig. 1. The diagram implies that any form of the command which is obtained by..traversing the graphin
the directions of the arrows is allowed. For example the commandSIHU O 1oO ï ,,
' l' t
simulates a system from time 0 to time 100.
If
we want to repeat the simulation asecond time with different parameters
it
suffices to writeSIHU
The previous values
of
thecommands are provided with default arguments. These arguments are then used unless otherwise stated,
"4
.ûafB¡rr6e¡ts,
i.e.
Oand
100,are
then used. MostTime increment
Stop time
SIMU
@
@
Fiqure 1. Syntax diagram
for
the command SIMU.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 continuedby
using the end conditionsof a
previous simulationas initial
values. Thisis
doneby the
command option CONT. Theresults of a simulation may also be stored
in
a file. The time spacing between thestored values is specified by increment.
The syntax
for
the simulation command may also be described as follows SIHUt
t t t
<start
time><stop
time>-{coNT l}IARK}l
[/<f
ilename>( increment>
(increment>
ll ll
This description
is
calledthe
Backus-normalform
(BNF),or the
Bachus-Naur form. (...> denotes an argument i.e. a numberor
an identifier.[al
a2...1 denotesoptional arguments which may be omitted and {al1"21...} denotes that one
of
thealternative arguments must be chosen. An asterisk (*) after an argument denotes
that
it
may be repeated.ffre synta|,foç
'rl åny commandis
obtainedby
typing the command HELP followed by the nameof
the command. The syntaxis
then shownin
the Backus-Naur notation. The syntaxof
the commandsis
givenin
Appendix Al', 4,¡ ".
T
CON
Filename Store increment
EXERCISES
1.
Learn howto
login
and log outof your
computer system and howto
getaccess
to
mass storage areas. Gethelp from your
systems manager if necessary. Document what you are doing so that you can repeatit on
yourown.
2. On the Vax
implementationsyou start
Simnon simplyby
typing Simnon.Simnon answers
by the
prompt>.
You canexit
Simnonby
typing STOP.Practice this.
3. Try
to find out about Simnon by using the command HELP.4"
Use the HELP command to find out how the command AXES works. F;<perimentwith the AXES command to find out how
it
works.ï
t' It t
tl
Itn tt,=-
3. Differential Equations
Solution
of ordinary
nonlinear differenüar equationsis a
simpre apprication of simnon'In
such appricationssimnon 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
carcuratora
functionis
activatedby
pushing a dedicatedkey' In
simnon functionsare
activatedby
typinga
commandon
thekeyboard' How sirnnon
may be
usedto
generate sotutionsto an
ordinary differential equation is illustrated by an example.THE PROBLEM
::iï::,,tÏt
we would like to know the character or the sorurion to the van der.2
#.^þ2-b)åT+y=o
(3.1)for
different initial conditions and different values of the parameters a and b. Thevan der pol equation is a model
for
an elqctronic oseillator.The path toward:
steps.
s
the solutiontolthe
Pçoblem can be dividedin
the following , lt Ii.
Enter system descriptions2.
Simulatenditions
il a
satisfactory resultis
obtained. The different steps will now be described in some detail.10
continuous system \|DPOL
"The van
der Pol
equationstate x
yder
dx dy dY=xdx=a*x*
(b-y*y)-y
Listine
1. A
Simnon systemfor
Equation (3.2)ENTER THE SYSTEM DESCRIPTION
The equation (3"1) is
first
rewrittenin
the standard state space form (2.1). Sincethe
equation (3.1)is of
secondorder an extra
variableis
introduced. The equation (3.1) can then be written asa:1 b:1
END
dv
ãî=*
(3.21
The
equationsare now in
standard state spaceform, which is the
format necessaryto
use Simnon"A file
which describesthe
system shouldnow
be prepared. Thisfile
whichis
labeled VDPOLis
listedin
Listing1.
Thefirst
line indicates thatit is a
continuous time systemwith
the name VDPOL. The statevariables
x
andy
and their derivatives dx anddy
are declared. The differential equations are then defined. Notice the strong similaritywith
(3.2)" Finally valuesare
assignedto
the parametersa
and b.-Simnon separates between
@g!g!Ë
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 notatio¡l '='.The
file
can be edited usingany
editoryou are
familiarwith.
Assuming the standard editor you type EDIT VDPOL,.Tif
you arein
VMS and $EDIT VDPOL.T ifyou are in
Simnon.In
the VÆf/VlfS systemall
Simnon system files have thel1 r t /
extension'.T'. This also appliesTto Mdcro files (Chapter 6). There
is
also a simpleline oriented editor
built
into Simnon which can be usedto
enter thefile.
Thiseditor is invoked by the command EDIT <filename>
where the argument <filename>
is
an identifier i.e.a
letter possibly followed by lettersor
digits. The facilitiesin
the editorare
describedin
AppendixA.
Thesyntax of the system descriptions is given in Appendix B. The command
LIST <filename>
lists a system description on the terminal.
SIMULATION
To
run
a systemit
mustfirst
be activated. This is done by the command SYST VDPOLlf
there are anyerrors
during the compilation anerror
message is given and the system enters the Simnon editor so that theeror
may be corrected.If
you want to use another editor simply type LEAVE to exit Simnon's editor.If
we would liketo
see the solution curves as they are integrated we must first draw axes on the screen. This is done with the commandAXESH020V-66
which means
that the
rangesof the
horizontal (H) and vertical(V)
axes are chosen as (0,20) and (-6,6).The command PLOT
x
yinstructs the program to plot the våniables'
x
andy
as functions of time.' l' '
To perform
a
simulationit is
necessaryto
give appropriate initial conditions tothe state variables. The command
INIT
x: 1,l
assigns the initial value 1
to
thþ tÞ variablex.
lnitial values are automatically made. Weare now ready to
perform a tft'atp
set to zero if no
assignments are simulation. The command6
4
2 2
2
1
2
1
0 ot
!c c H
! Jc)
Lß E tì
!E a!
x o
¡
a,C.;
G (, +t.l +) al,
1
-2 2
-4
-6
0 t0 15 20
Timc
t
Figure
2.
Simulationof
the vander
Pol equationfor a=l
andb=l with
initial values x(0)=1 and Y(O)=g.SIHUO20-HARK
activates a simulation from time O
to
time 20, and the result shownin
Fig.2
is obtained. The argument -MARK implies that the curves are labeledwith
integersL,2u.. in the order they appear in the plot command.
5
HOW TO INTERRUPT
A
SIMULATIOfr' I'
b
I
Some times when you make a simulation you
will
find that the results are wrong at the beginning.It is
then useful to'be able to break the simulation immediately.There
are
facilitiesfor
doingthis in
Simnon. The detailsare
implementation dependentCTRL-C.
On the standard V"¡"!y4¡"rns the simulation
is
interruptedby
typingltt
CHANGING PARAMETERS
Suppose that
it is of
interestto
explore howthe
characterof
the solution is influenced by the parameters a and b. The commandPAR b:2
assigns the value 2 to the parameter b. The command SIHU
now generates
a
new simulation. Notice thatit is
not necessaryto
specify any argumentsin the
command SIMU. The previously given values0
and20
are automatically used as default values. The useof
default values simplifies the user interaction considerably.It is
now easyto
continueto
explore howthe
solutionis
influencedby
the parameters of the solution by a repeated use of the commands PAR and SIMU.Curent
valuesof all
states, derivatives, variablesand
parametersmay
bedisplayed. The command DISP
displays
all curent
data. Selective displaysof
the parameter a, the statex
andthe variable
y
is done by the commandDISPaxy
The display may also be directed
to
the lineprinter. A
simple wayto find
out how the command DISP works is to typeHELP DISP
The help function can be applied to all commands
I'
, l' t
STORING AND EDITING RESULTS OF
A
SIMULATIONtt may be
usefulto store
some results,to
compareresults from
different simulations and to plot'
different,'J-ta/e-|*,
variablesin
different diagrams. Supposefor
"
example that we would like
to
compare the resultsfor
the parameter sets a=1,b=l
with a=!, b=2. Two data files arefirst
generated. The commandPAR a:1
PAR b:1
sets the parameters. The command STORE
x
ytells that the state variables
x
andy
should be stored. The command srHU/B1then performs a simulation and stores
x
andy in
a file called 81. The valueof
b is set to 2 byPAR b:2 and the command
srMU/82
simulates and stores the results in file 82. The command SPLIT
2
1splits the screen into two windows. The command ASHOI{ x/82
plots the variable
x
from file 82in
thefirst
window using automatic scaling. The commandSHOI{ x/81
plots the variable
x
from file 81 in the same window. The commands ASHoll y/82SHorl vlBL
plots the variable
y
frorn files 82 and 81þ
the second window. To document theresults
it is
usefulto
generatea
hardcopyof
the curves obtáined. The details depend on the hardware. On a norrLal insNallation the command, l' t
HCOPY
sends
a
copyof the
pictureon thg
screento the
plotter queue. The results shown in Fig" 3 are then obtained. Thê commandsPLIT
1 I ,"î, f,
l'*
clears the screen and resets plotting to one window which covers the full screen.
6
0 x
¡
o.;al 3!
+to
{Jlt
U' -6.
0 10 15 20
Ti¡ne t
-3.
0 15. 20
Timc t
Fisure
3.
Solution of the van der Pol equationfor
b = 1 and b = 2.PHASE PLANE PLOTS
For two-dimensional differential equations
it is
usefulto
visualize the results asphase plane plots. This may be done simply by
AXESH-44V-33
SHot{
y(x)/41
which generates Fig. 4.+ ,
I' l' t
GENERALITIES
The general way
of
using Simnon asa
'calculatorfor
differential equations" will now be given. The genericfor?'{f
drsystem description is givenin
Listing2.
Trre system description starts with CONTINUOUS SYSTEM <Identifier>.It is
terminatedby a line which contains END.
An
identifieris
a a sequenceof
letters and digits5
3
0
a,
Itc
.;
o
+to
4Jn
U)
5 10
3
2
1
0
3
'l
@
.oo
.;
I
+to +tñ
al,
-1.
-2.
-4"
Statc variable ¡
-2
Figure 4. Phase plane plot of the van der Pol equation
for
a = 1, b = 1, x(0)=
1,Y(o) = o.
2 4 0
CONTINUOUS SYSTEH <Identif ier>
"GeneraI
differential
equationstate <Identifier>.
..<Identifier>
der <Identifier>.
..<Identifier>
time <Identifier>
computation
of auxiliary
variables computationof derivatives *
parameter assignment
initial value assigrunþnt
,END , t, I
Declarations
t
en
Comm
Bodv
Listine
2.
Genericform of
system descriptionfor
simulationof
differential equations.where the
first
character mus letter. Both upper and lower case letters maybe
used althoughthe
compiler doesnot
distinguish between them. The'4
,tfi,,!'|lt,i
tbea
system description has two parts, a declaration and a body
There
are three
typesof
declarations.A
time variable maybe
declared for simulationof
time varying differential equations. Thisis
doneby
the keyword TIME followedby an
Ídentifier. The state variables andtheir
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 bea
string,a
numeric constantor
avariable.
It
may alsobe
combinationsof
variables, operatorsand
functions.Conditional expressions
of
the form ¡F...THEN...ELSE are also permitted. Simnonhas arithmetic, relational and logical operators.
All
variablesare
floating point numbers. The numbers are writtenin
the conventional way as 4, 1.1or
6E7. Theresult of boolean expressions
is
1.0if it
is true and 0.0if it
is false.Arithmetic operators
The arithmetic operators
are
addition, subtraction, multiplication, division and exponentiation. They are denoted as+-* |
respectively.
Relational
operators +
I, l' I
There
are three
relational operators, namely equal, greater than, and smaller than. They are denoted bY=><
Logical operators
The logical operators are AND, OR and NOT.
t,¡
|
^,'
',Functions
The following functions are available:
abs
(x)
absolute value sign(x)int
mod max
min(x,y sqrt (x) exp (x) Itr ( log
sin
cos
tan
{l
x<0x=0x>0)
x) xrY X,Y
largest integer less
than xxmody
Iargest of x
and ysmallest of x
and y sguareroot of x,
x)0 exponentialfunction natural
logarithmof
xlogarithm
(base 10)of
xsine of x (x is in
radians) cosineof x (x is in
radians) tangentof x (x is in
radians) arcsinearccos
arctangent
of x result in
(-n12, arctangentof x/y result in (-n, hyperbolic
sinehyperbolic
cosinehyperbolic
tan x)(*) (*)(*)
(*)
arcs
in
erccos
(")
(*) atan (x) atan2 (sinh(x
cosh (x tanh ( x
dx
Ar
=
f(x,t).
"l
2lr)
x,Y)
) ) )
SUMMARY
It
has been demonstratedthat
Simnon maybe
usedto
generate solutions toordinary differential equations
in
avery
simple way. To do this the differential equations arefirst
written as a system offirst
order equations like+
, l'
I
4
A
continuous time systemis
then generatedin
Simnonby
declaring the state variables and the derivatives. The fuhction f, which defines the right hand side ofthe differential
equation, isexpressions and assignments
equations must be written
in
scalar notation.Any
editor may be used. There is also a special editor incorporated into Simnon, whichis
invoked by the commandthen
introducedusing ordinary
mathematical,l
,,of pah¡meters. There
is
no vector notationso
allI t. tl
EDIT. The command LIST can be used to list files.
A
simulationis
executed using six basic commands: SYST, AXES, PLOT, IIJIT, P.A'R and SIMU.In order to edit,
manipulateand
documentresults from
several different simulationsit is,
however, also usefulto
usesix
additional commands, namely STORE, SHOW, DISP, SPLIT, AREA and HCOPY.The HELP command is useful in order to see what the commands do.
EXERCISES:
t
Learn howto
use an editor onyour
system. Practiceby
editing the systemin Listing 1.
2.
Learn howto
enter and exit from Simnon. Use the command LIST tolist
the system you have edited on the screen and on the lineprinter.
(Notein
theVax implementation you may invoke
a
program called PRG from Sir:nnon by typing $PRG without leaving Simnon.)Repeat the simulation described in this chapter on your own.
Change parameters
with the
command PAR andinitial
conditionswith
thecommand INIT
and
investigatehow the
solutionsto the van der
Pool equations change.5.
Experiment with the commands AXES, SPLIT, SHOW, ASHOW and AREA.6.
Use the HELP commandto
investigate the basic simulation commands AXES, PLOT, INIT, PAR, SYST and SIMU.7.
Introducea formal error in the
programin
ListingI by
changing theassignment
of dx to
dx = ar,x*(b-y*y-y.Try to
simulatethe
incorrect program. (Whenan error is
detectedthe
command EDITis
automatically executed. You maycorect
the mistakê using the line editor. The simulation is then automatically continued when you exit the editor by iyping E" You canalso leave the editor
by
the cq¡nman{ LEAVE and useyour
favqurite editorforthecorrection.) ,It t
8.
Use the HELP command to investigate the auxiliary commands STORE, SHOW, DISP, ASHOW, SPLIT and AREA.3 4
9.
Look at the commands LIST, LP eind HCOPY and learn how to get hardcopiesof listings and plots on youtî,fsYftem.
h,,!
r|
10. Consider the following van /dejr Pbl equation
€t+ (v2-t) ü*Y=a
Investigate the limit cycles obtained
for
e = 0.05 and 0.993(
a(
1.11.
The
following equations calledthe
Volterra Lotka equations represent asimple model
for
the development of two competing species dxä=(a_by)x
åT=(cx-d)y
Make
a
Simnon programto
studythe
equations. Startwith the
following nominal values: a o 2.7,b = 0.7, c=
1 and d = 3.72.
A
simple modelfor
a satellite orbit is given byd2"
l-l=_-la'12
kdtz ldtj .2
&
dt2
+-
2r dr dt dt
d<p =Qwhere
r
is the radius from the center of the earth, g the azimut angle and k a gravitational constant. Simulate the equations.13. Learn how to interrupt a simulation on your installation.
L4. Simulate the differential equation dx
ä="(v-*) , x(o) =-a
dy
dt
dz ãT
=
bx- y - xz, y(o) =
-a=-cz *xy, zl9l=24
where a = 10, b = 28 and c
=
813, Lookin
particular atz
as a function of x.The
equation,which is
calledthe
Lorenz equation,is an
exampleof
adeterministic system, which has a very, irregular (chaotic) behavior.
\ , l'
¡ .l
tf
.¡Itc
l',4. Difference Equations
There
are
also facilitiesfor
simulating difference equationsin
simnon. This is done analogously to simulation of differential equations. An exampleis first
given and the general principles are then stated.EXAMPLE
Consider the following difference equation
*k*1 = *k *. * xk * (l-xk) , k
=0,1,...
(4.1)This
is a
simple modelof a
population dynamics. The variablexu
denotes thenumber
of
individualsat
timek in a
normalized scale. Thereis
an equilibrium valuex=l at
whichthe
population remains constant.For
xnæothe
population increaseswith
thefactor 1+r in
each generation. Forxu>l
the population will decrease' Assume thatit is of
interest to investigate how the population changes with time.A
difference equationis
characterized asa
DISCRETE SYSTEMin
Simnon. Thedescription
of
a system which simulates the difference equation (4.1)is
given inListing3. + ,
!The state variable
x is
declaredin',rl"'
""1"
way asfor
continuous time sysremusing the srATE declaration. The declaration NEW is used to declare the variable nx, which denotes the new value
of
the,state variable. NEW is thus the analog of DERfor
continuous time systems.,{
,il',f'
when simulating difference equations
it is
necessary to provide a mechanism formaking the state variables change at certain sa¡npling times. For example the state
discrete
system POPDYII"Simple model
for
population dynamicsstate
x new nxtime
k tsampts
nx=x+r¡r x* (
t-*)
15=tç+1 x: 0.5
r:2
END
Listins
3. A
Simnon systemfor
simulation of the difference equation (4.1).variable in equation (4.1) changes periodically at k
= !,2, ....
In the general casethere 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 definitionof
the right handside
of
the difference equation (4.1). The second line:ts=k+l
assigns the valuek+l
to the TSAMP variable ts. This tells that the systemwill
be activated next at time k+1.SIMULATION
Discrete time systems are
run in
the same way as continuous time systems. A simulation is thus executed by the commandssyst
popdynsplit 3
1axes H080V01
plot x X ,r
simu 0 80 , l) t
This generates the uppermost curve
in
Fig. 5. The commands axespar
r:2.7Os imu
axes
par r:2.83
simu
t f,,
t,,
x co
;
af
CLo o-
0 ot
;
ñaê
ô-o
0 co
;
ñfê
o-o
0.75
0
0 20 40. 60 80
0.75
0 20 40 60
0.75
60 80
Fisure
5.
Simulation of population dynamics.repeats the simulation
for r =
2.7O andr =
2.83, and plots the correspondingcurves
shownin Fig. 5.
Noticethat the
behaviourof the
solutions changedrastically with moderate changes in the parameters"
80
0.
Gcneration k
20 40
GRAPHS OF
FUNCTIONS ï ,
), l' .t
Simnon is conveniently used to obtain a graph of a function. Assume
for
examplethat we want a graph of the polynomial
f (*) =
x(x+3) (x+2) (*-21(x-e).ti
JThis is accomplished by the folloþtr,f tçyst"-.
150.
f (x) 100.
50.
- 100
- 150
-4
Fieure
6.
Graphof the
function f(*)Simnon.
discrete
system POLtime
xtsamp z
¡=(x+3)* (x+2)*x* (x-2)* (x-3) 2=¡*dX
dx:0.05
END
The commands
th
syst
polstore f
simu
-3.6
3.6ashow
f
, l'
2 4
x(x+3)(x+21(x-21(x-3) generated by
0
-50
0
x
t I
will
then generate Fig. 6."t
Simnon
is also
convenientfy î.Éeå/tto 'f generatelevel
curves,field plots
andconformal maps. To illustrate such applications consider
for
example the problem;t"jt"ot"t
the image
of
the lines argz ;
trr2 and argz
=3rr.in
the conformarG(z)
=
", = "*=iy = "*("os y + i sin y).
This may be accomplished by the s!¡stem
discrete
system El(pZ timer
tsamp s
fi=atfa*pi/ tg}
x=r*cos
(fi
)y=r* s in
(fi
)ReG=exp (x) * cos (y) ImG=1xp(x)*siniyj s=r*dr
dr:0.01
pi:
3. 74t5926alfa:
g0END
The commands
syst
EXpZaxesh-11v0l.s plot
ImG(Rec)srmu
0
3.14par alpha:
13Ssimu
0
4.44then generate the graph shown in Fig. Z.
GENERALITIES
SUMMARY
The generar form of a description of a discrete'.rime system
is
givenin
Listing 4.It
is analogous to the continuous tim,the sampting variabte TsAMp must
b: :1t-Ï
,Tlreonlv semantic difference
is
thar e assjøneC and that der is replaced by new.Difference equa ions are simutated in
rl, (r,n"
way as differentiar equarions. TheSYSTEM
dESCriPtiON DISCRETE SYSTEM iS USEd iNStEAd Of CONTINUOUS SYSTEM.
26
1.5 Im0
L.25
0.75
0.5
o.25
Fisure
7.
Graph of map G(z)1
0
1 -0.5 0.5
ReG
thermap
of
therays
argz = r.II
and argz = 3rl4 in
the=e.
0 1
discrete
system<identifier>
"general
difference
equationstate <identifier>...<identifier>
new <identifier>.
..<identifier>
time <identifier>
tsamp <identif ier>
'Écomputation
of auxiliary
variables computationof
new vafuesof the
states updatethe variable
T¡gmprparameter assignmeni'
initial value
assignmentEND
comment
declarations
body
Listins
4.
Structure of Simnonï/tF* for
simulating difference equations l¡n 'Il't
The simulation commands are the same as
for
differential equations, i.e. six basic commands AXES, PLOT, INIT, PAR, SYST and SIMU andsix
auxiliary commands STORE, SHOW, DISP, SPLIT, AREA and HCOPY.t
) , lr
lr
|','"
EXERCISES
1.
The difference equation+-
a*kis a well
known algorithmfor
computingthe
squareroot of a. Write
adiscrete system in Simnon and explore the algorithm"
2.
Modify the simulation program in exercise 1 so that the stationary solution tothe equation is cornputed and plotted.
3.
The following is a simple Keynesian model of a macro economic system= c(t) * i(t)
+g(t)
= â Y(t-t)
= b [c(t) -.(t-1)]
where
y is
the gross national product,c
consumption,i
investment and g government expenditures.Write the
equationsas a
systemof first
order equations and simulate the equations. Investigate the responseof
the systemto a sudden increase
in
government spending. What are the influences of the parameters a and b?Try
the values a = 0.75 and b-
0.5, 1 and 2.4.
Investigate the properties of the following difference equation 2yzl
exp [-o.t(*2
*r*r = å (*r
(t) (t) (t)
v c
i
r
x
x(t+l)
y(t+r)
x+ +
v2)f
t)
for
different values of the pararneterr.
r , l'
.tf f,
I
5. Combination of Systems
It is
often usefulto
structurea
large probleminto
smaller subproblems. Insimulation
this is
doneby
decomposinga large
systeminto
interconnected subsystems.A
subsystemis
often represented as a box with inputs and outputs and the interconnectionsare
representedby
directed lines between the boxes.Such
a structure can be
representedin
Simnon.This is
doneby
adding declarationsof
inputs and outputsto
the system descriptions. The subsystemscan then be described as
a
CONTINUOUS SYSTEMor a
DISCRETE SYSTEM. A special typeof
systemis
usedto
describe the interconnections. This system is called a CONNECTING SYSTEM.Consider
the
control system shownin
Fig.8
whichis a
combinationof
twosubsystems
discrete
system REGinput yref
youtput
uEND
continuous system PROC
input
uoutput
yI
, ì'
t
?
END
and the system which describes the iriterconnection is given by
.t
,,ll'l f' lt
REG PROC
r
Figure
8.
Block diagram of an interconnected system' connecting sYstem CON"Connecting system
for simulation of
process PROC"with PI regulation
by system PIREGtime t
yrIpireg]
=1yIpireg]=yIproc]
uI proc ] =uIpireg
]
END
Notice
that
states, variables,and
parametersare local
variablesin
eachsubsystem. Variables
in
different subsystems maybe
specifiedby
adding the system namein
square brackets after the identifier. Also notice that expressions may be used to describe the interconnections. constructions likey[reg] = if t<l
then0 else sin(k*v[proc])
are thus possible.The simulation
of
an interconnected system is done using the same commands as was usedto
simulate differenceor
differential equations. The only difference isthat
it is
necessaryto
activateall
subsystems that describe the interconnected system. This is done bY the commandSYST SYS1 SYSz CON
The connecting system must be the last system
in the list'
Theorder of
the systemsis
otherwise irrelevant. Contir,trä,'r, and discrete system may be mixedfreely. + ,
¡, lt t
AN EXAMPLE
-
SIMULATION OF A COMPUTER CONTROL SYSTEMA
continuoustime
processïtÍtv¡
computercontrol
systemis
conveniently described as an interconne"t"h'=yJtem. The process may be represented as aCONTINUOUS SYSTEM and the control computer as a DISCRETE SYSTEM'
discrete
system PIREG"PI regulator with
anti-windupinput yr
youtput
ustate i
new
ni time t
tsamp
ts
e=yr-yv=k* e+i
u=if
v<ulow then ulowelse if
vcuhigh then v ni=i+k* erh/ti+u-v
ts=t+h k:1
ti:
Ih: 0.5 ulow: -1 uhigh: 1 END
else
uhighconnecting system CON
"Connecting system
for simulation of
process PROC"with PI regulation
by system PIREGtime t yrIpireg]=1 yIpireg]=yIproc
uIproc]=uIpiregEND
l l
Listins
5.
Sirnnon descriptÍon of a simple control loop consistingof
a continuous time process and a discrete time PI regulator.Listing 5 describes a feedback loop consisting
of
a continuous time process called PROC and a digital PI regulator called PIREG" The processis
an integrator with input saturation. The interconnectþns ,ar,e describedby the
connecting systemcoN. , t' t
4.t
ln f I
Command
syst proc pireg con store
yr
y[proc]tpt
simu 0 40
split
2
1ashow
y yr
The following annotated dialogue illustrates how Simnon is used.
ashow upr
Action
Activate the system.
Select variables to be stored.
Simulate.
Form two screen windows.
Draw y and yr with
automatic scalingin
firstwindow.
Draw upr with automatic scaling in second window.
Notice
that the
namesare
localto
each subsystem.To
distinguish between variables that occurin
different subsystem the nameof
the subsystem is written in square brackets asin
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. Thediscrete nature
of the
control actions generatedby the
computerare
clearly visiblein
the curves. These curves show that thereis
a considerable overshoot dueto
windup at the integral. Thisis
avoidedby
telling the regulator what the process limitations are. The commandspar
ulow: -0.1par
uhigh: 0.1changes the necessary parameters. The commands
simu
0
40area
1 I
show
y yr
area2
Lshow upr
\ ,,
shows that the overshoot is reduceflrsignificantly. Compare Fig. 9"
GENERALITIES
¡."t f
Simnon allows three types
of
sþ3terl,. descriptions, namely CONTINUOUS SYSTEM, DISCRETE SYSTEM and CONNECTING SYSTEM. The discretE ANdthc
CONtinUOUs0
la-o L
! co
+tf +)e oJ
T,2
0"6
0 10 20. 30. 40
0.1
-0"1
0 10 20 30 40
Time t
Figure 9. Results
of
simulationof
process controlwith a pl
regulator. Thecurves
with
a large overshoot correspondto
an ordinary regulator.The other set of curves are obtained with a regulator with overshoot inhibition.
systems may be simulated individually provided that
no
inputs and outputs are declared. Interconnected systems may also be describedby
using the connecting system. The complete syntaxfor
the system descriptions is given in Appendix B.EXERCISES 0
J o
áo
.;
n
ãL {t co Lì
I
2
Look at the syntax of the comnTands SIST and SIMU using the help command.
what are the
differences, údtwåen simulationof single
systems and interconnected systems.The HELP
command hasexperimentally.
an hierarchical structure. Explore
thisy',"
f I
â34