Upload
pradeep-kumar
View
217
Download
0
Embed Size (px)
Citation preview
7/29/2019 regeng
1/60
RegSim
MANUAL
Thomas Gustafsson
October 2003
7/29/2019 regeng
2/60
Contents
1 Introduction 3
2 Model Language 4
2.1 Introductory Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Definition of Name and Type of Systems . . . . . . . . . . . . . . . . . . . . . 62.3 Definition of Special Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.1 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Initial values for states and outputs . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Describing the process mathematically . . . . . . . . . . . . . . . . . . . . . . 10
2.6 Combining Different Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.6.1 Connecting System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.6.2 Without connecting system . . . . . . . . . . . . . . . . . . . . . . . . 11
2.7 Examples of some system descriptions . . . . . . . . . . . . . . . . . . . . . . 11
2.7.1 Second order differential equation . . . . . . . . . . . . . . . . . . . . 11
2.7.2 Third order differential equation . . . . . . . . . . . . . . . . . . . . . 132.7.3 Data acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.7.4 Matrix Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 The RegSim Commands 16
3.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 How to give arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.1 Method 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.2 Method 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.3 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 History of command given . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4 The Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4 Command Files 57
4.1 Invoking by a MACRO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5 The Syntax for Expressions 59
Regsim 3.8
7/29/2019 regeng
3/60
Chapter 1
Introduction
In your hand you are holding a document which gives the directions for RegSim, a programme
that is very useful in developing and testing of control engineering projects. Furthermore, thanks
for the general nature of this programme its application area is quite wide.
With RegSim one can:
Simulate arbitrary combination of continuous time and discrete time systems. Thesesystems can be linear or non-linear.
Can drive discrete systems in real time using the facilities provided to communicate with
real world using A/D and D/A card.
Presents simulation or real time results graphically. This also gives the possibility foranimation.
A new way to work
Think of this possibility.!! You can develop and test a new controller design for a process, and
this work usually includes few steps.
1. Identify the process, and develop a mathematical model for the process
2. Design a controller
3. Test the controller function through the simulation of the process and the controller.
4. Test run of the controller
All who have tried this task one time or another have definitely experience how the first test run
went wild without one knowing what really went wrong. It is in this aspect the RegSim gives a
big advantage. You can really use RegSim both in phase 3 and 4, with the same controller. That
is, just by simple command you can drive the controller with the simulated system or with the
real process. In this way one can compare the reality and the system model.
Regsim 3.8
7/29/2019 regeng
4/60
Chapter 2
Model Language
Any process that you intend to simulate must be described in a way the RegSim understands.
The RegSim supports the simulation of both Continuous Time Systems and Discrete Time Sys-
tems. A RegSim programme to simulate a large process can be in one file or it can be divided
in to subsystems, and each can be implemented in different files. Each of these RegSim files
which describes either a whole system or a subsystem must contain the following parts.
Definition of name and type of the system
Declaration of the special variables
Give initial values for the state variables and the output variables
Mathematical description of the process
END
2.1 Introductory Example
This example shows how we can describe a first order differential equation and simulate it for
different input signals using RegSim.
Differential equation is given by
x = a (u(t) x(t))
The translation of it into the RegSim system isCONTINUOUS SYSTEM first " defines the name "first"
STATE x " declares the special variables
DER dx " derivative variable of the state x
TIME t " declares the time variable
d x = a*( u - x )
u = IF t > 5 THEN 0 ELSE 1 " u is a unit step starting at t = 5.
a : 0.4
END
If this RegSim programme is stored in the file first.t, then to simulate it we must first compile
it using the command COMP.
First to invoke RegSim give the command ega (or cga) to invoke the appropriate graphics driver,
Regsim 3.8
7/29/2019 regeng
5/60
2.1 Introductory Example 5
and then give the command REGSIM. Once the REGSIM is invoked and the cursor >> appear-ers in the command window give
comp first.t
to compile the system. If you like to see how the variable x changes, then give
plot x
To initialize the state of the differential equation give
init
simu
This will give the curves shown in figure 2.1
Figure 2.1: First order system
If you want to repeat the simulation with a = 0.7, then you give the following commands
par a 0.7
init
simu
Regsim 3.8
7/29/2019 regeng
6/60
6 Model Language
2.2 Definition of Name and Type of Systems
A system can either be a continuous or a discrete time system. The first line of the RegSim
program indicates this.
CONTINUOUS SYSTEM
or
DISCRETE SYSTEM
There is also a third type known as the CONNECTING SYSTEM and is described in section 2.6.
2.3 Definition of Special Variables
A variable is classified in two different ways, what type of value it has ( Boolean, Real or
Matrix) and what the function of the variable, i.e if it is an input, output, state or a parameter,
RegSim can automatically recognize variables of types Real and Matrix and if the functions are
parameter, output or a basic variable.
For other kinds of variables it is necessary to deklare either the type or the function before it
can be used. A deklaration is of the form
...
where is one of:
INPUT These variables get there values from other systems. See example of use in
section 2.6.1.
OUTPUT These variables are marked as the ones that can be used by other systems. If an
undeclared variable is used from another system, then it is automatically marked
as an OUTPUT variable. Hence this command is functionally redundant, but
increases the readability of the programme.
The variables of OUTPUT type can be assigned a initial value.
TIME If you wish to have access to the time, a variable name has to be declared for
time.
STATE Declaration of the State variables. This can be assigned a initial value. Default,
the initial value is taken zero.
DER Used only in continuous systems to declare the derivative of the state variables
declared under STATE. The derivatives should be declared in the same order as
the states are declared in STATE. With the following declaration
CONTINUOUS SYSTEM MOTORSTATE x y
DER dx omega
Regsim 3.8
7/29/2019 regeng
7/60
2.3 Definition of Special Variables 7
then x and y are states, dx and omega their derivatives, i.e dx = x andomega = y.
NEW Used only in discrete time systems to declare the new value of the state variables
declared under STATE. NEW is similar to DER in continuous systems. The the
NEW variables should be declared in the same order as the states are declared
in STATE. With the declaration
DISCRETE SYSTEM CONTROL
STATE z c
DER nz qw
TSAMP ts
TIME t
ts = t + h
then z and c are states, nz and qw are the new states, i.e z(t + h == nz(t) andc(t + h) = qw(t). From this one understands that the states z and c cannot begiven values explicitely, this is done automatically by RegSim that assures that
the states will have the correct values in the beginning of each sample.
TSAMP Must be included in discrete time systems to specify when the next sampling
should be made. When the RegSim is driven in real time (REGU), the sampling
time is decided by the variable SAMPTIME which is in every discrete time
system. To get the same sampling intervall both during simulation and real-
time control do something like this
TSAMP tsTIME t
ts = t + samptime/1000
MATRIX MATRICES and VECTORS can be declared. This can be done in any of the
above declarations (STATE, DER, NEW, INPUT, OUTPUT), or with MATRIX.
INTEGER Declaration of whole numbers.
BOOLEAN Declaration of logic variables.
2.3.1 Global Variables
In RegSim there is a number of Global Variables.
Simtid Defines how long the simulation has to be done (Simulation Time). The simula-
tion time has nothing to do with real time. The simulation time can be faster or
slower than the true time. There is a possibility of synchronizing simulation time
with real time. See command PLOT for more information.
Minstep The minimum step size in the integration routine. If this step length is used many
times during the simulation, then a message is given after the simulation.
Regsim 3.8
7/29/2019 regeng
8/60
8 Model Language
Break When the time given by break is reached the simulation is stopped, and requests
for a new break time that gives the next time instant the simulation has to be
stopped.
Epsilon With this variable we can define how accurate the simulation must be. The normalvalue is = 104, and this means that the absolute value of the mean value of thestate variables relative error shall be less than 104.
Tid Contains the simulated time.
Inttime Resolution of the real time clock in milliseconds. Maximized by the programme
so that a little time as possible is taken for the administration of the real time
kernel.
If for example two discrete time systems have sample time 20 and 50 millisec-
onds respectively, then the Initime is set to the greatest common denominator, i.e.10 ms. If the sampling times are 21 and 50 ms, then Initime is set to 1 ms, to
guarantee that both the processes are executed at the correct time instant. The
real time kernel works 10 times faster than before and this is often noticed in the
plotting.
Samptime This variable is declared in all the discrete time systems and used to decide the
sample time when used in real time (REGU). Samptime is a whole number which
is given in milliseconds. In simulation used with TSAMP.
Samptime need not to be declared and may simply assigned a value either in
INITIAL block or using PAR-command.
@ The variable used in the command Graph.
Regsim 3.8
7/29/2019 regeng
9/60
2.4 Initial values for states and outputs 9
2.4 Initial values for states and outputs
RegSim has a command Init which must be given before a new simulation. The command
assigns a known inital value to all state and output variables that usually is equal to zero. Ifvalues other than zero is needed, they can be given in two ways. One can use the command
PAR, or declare the initial values in a block in the RegSim programme.
This block starts with INITIAL and ends with SORT, and in between all the initial values are
assigned according to the following syntax,
STATE x1 z{3} yOUTPUT cont
INITIAL
styr = 0.45
x1 = sin(p)
z = {1,0,0}SORT
The example will only work if p is either a parameter or a timeindependant variable.
It is not possible to change a initial value given in this way.
If you are changing the initial values often, and hence wish to store a set of initial values so that
they can be used later, the command SAVE can be used to save them. The command LOAD
can be used to retrieve them.
Regsim 3.8
7/29/2019 regeng
10/60
10 Model Language
2.5 Describing the process mathematically
After all necessary declarations follows the mathematical description of the process one likes
to simulate. The mathematical description consists of the following two types,
variablename = arithmetic expression
or
variablename : numerical value
The first of them describes how the value of a variable could be computed while the other defines
a parameter. The difference is that a parameter normally has a fixed value during the simulation,
but with the help of a command the value can be changed during or between simulations. A
variable, one cannot change the value (except the initial values of state variables and output
variables), and is decided by the expression.
The order the mathematical expressions are written in the RegSim programme is not important
because RegSim sorts all the mathematical expressions in the order they are executed, and each
variable and parameter has a value when they are been used. However, algebraic loops of
following type are not permitted,
c = sin(t)
a = b + c
b = a + c
Furthermore a variable or a parameter should not be on the left hand side more than once. Ifthis is done, the sorting of the expressions can not be done by RegSim.
During sorting the different expressions are also classified in the following manner, Time in-
variant, Derivative computation, Continuous and Time Discrete. Such classification helps very
effective computation. The normal user usually does not notice this, but can be seen when
command DEBUG is used.
2.6 Combining Different Systems
Let the total process we wish to simulate is as shown in figure 2.2.
- - - -
6
Regulator Process
Givare
ref yu
yg
Figure 2.2: A feedback control system three different sub systems
The three systems, namely the process, the sensor and the controller can be combined together
to define a complete feedback control system. This can be done in two ways.
Regsim 3.8
7/29/2019 regeng
11/60
2.7 Examples of some system descriptions 11
2.6.1 Connecting System
The first approach uses an additional system, the so called CONNECTING SYSTEM, where
all the couplings are specified. In our example it looks as follows,
CONTINUOUS SYSTEM reg
INPUT e
OUTPUT u
u = .......
END
CONTINUOUS SYSTEM process
INPUT u
OUTPUT y
y = .......
END
CONTINUOUS SYSTEM givare
INPUT y
OUTPUT yg
yg = .......END
CONNECTING SYSTEM conn
y[givare] = y[process]
u[process] = u[reg]
e[reg] = ref - yg[givare]
ref : 1.5
END
2.6.2 Without connecting system
Taking that all the variables are global, it is possible to couple different systems without us-
ing the connecting system. If a variable from another system is referred to, then it is done
by using the variable name with the system name inside the square brackets, i.e. varaible-
name[systemname]. The above example would then look as follows,
CONTINUOUS SYSTEM reg
OUTPUT u
e = ref - yg[givare]
u = .......
ref : 1.5
END
CONTINUOUS SYSTEM process
OUTPUT y
u = u[reg]
y = .......
END
CONTINUOUS SYSTEM givare
OUTPUT yg
y = y[process]
yg = .......
END
2.7 Examples of some system descriptions
2.7.1 Second order differential equation
The non-linear second order differential equation considered here is the van der Pols equation,
x + (x2 1)x + x = 0
Regsim 3.8
7/29/2019 regeng
12/60
12 Model Language
We want to find (plot) the phase curves, i.e. x vs x for different initial values. To do this thesecond order system is first described as two first order differential equations by defining the
following two state variables,
x1 = x
x2 = x
The the van der Pole equation can be written in two first order differential equations as follows,
x1 = x2
x2 = (x2
1 1)x2 x1
The corresponding RegSim code is given by
CONTINUOUS SYSTEM Pol
STATE x1 x2
DER d1 d2
d1 = x2
d2 = -( sqr(x1) - 1 )*x2 - x1
END
To draw the phase plane plot shown in figure 2.3, the following commands were given,
scale -x -5 5 -y -6 6
plot -x x1 x2
Figure 2.3: The phase plane for the van der Pols equation
(The -x option in the plot command is given to plot between x1 and x2. If -x option is not given,
i.e. plot x1 x2 then the default x-axis is the time axis.)
Now select suitable initial value for the states x1 and x2. The phase plane shown in figure 3 can
be obtained if the simulation time is set to simtid = 20, and the following initial values for
(x1,x2) are used.
(-3,5), (-2,5), (3,5), (-5, 0), (-0.01,0), (0.01,0), (5,0), (-3,-5), (2,-5), (3,-5)
The RegSim commands are as follows,
par x1 -3;par x2 5;init;simu
Regsim 3.8
7/29/2019 regeng
13/60
2.7 Examples of some system descriptions 13
par x1 -2;init;simu
par x1 3;init;simu
par x1 -5;par x2 0;init;simu
par x1 -0.01;init;simu
par x1 0.01;init;simu
par x1 5;init;simu
par x1 -3;par x2 -5;init;simu
par x1 2;init;simu
par x1 3;init;simu
2.7.2 Third order differential equation
The third order linear differential equation is given by
d3y
dt3+ a1
d2y
dt2+ a2
dy
dt+ a3y = Ku
This third order differential equation can by described by three first order differential equation
as follows by defining the state variables x1 = y, x2 = dx1/dt and x3 = dx2/dt.
dx1dt
= x2
dx2dt
= x3
dx3dt
= Ku a1x3 a2 x2 a3x1
The output is given by
y = x1
The corresponding RegSim programme is given by
CONTINUOUS SYSTEM third
STATE x1 x2 x3
DER dx1 dx2 dx3
OUTPUT y
TIME tdx1=x2
dx2=x3
dx3=K*u-a1*x3-a2*x2-a3*x1
y=x1
a1:1
a2:.5
a3:.1
K:1
u:1
END
Any higher order ordinary differential equation can be implemented in RegSim, by describing
it by all first order differential equations in the same as given in this example.
Regsim 3.8
7/29/2019 regeng
14/60
14 Model Language
2.7.3 Data acquisition
This example shows how a measurement from the real world e.g. water level, voltage, temper-
ature etc., can be obtained provided that the appropriate interface facilities are provided. Alsonote how SAMPTIME and TSAMP is used.
DISCRETE SYSTEM accqu
TSAMP ts
TIME t
INITIAL
samptime = 100 " sampling interval = 100 ms
SORT
ts = t + h " This is used with
h = samptime/1000 " simulation
out = daut(0, rand (umin, umax)) "sends an output signal
umin: 0 "minimum output signal [volt]
umax: 10 "maximum output signal [volt]
in = adin(0) "inputting a signal from channel 0
END
For data acquisition using the above programme which is stored in file dacc.t, the following
MACRO (daccqui.mcr) can be used.
MACRO daccqui period filename
"filename - name of a file that is used in the macro
"period - is a parameter, the value of which is passed to the macro
"DACCQUI - the the name of the macro fileecho off
COMP dacc.t
SCALE -x 0 100 -y 0 10
PLOT in out
PAR samptime $(period)
STORE -f $(filename) in out
CLEAR
WRITE Press F8 when data acquisition is over
REGU
To analyse the collected data, one can use for example MATLAB. To be able to do this, the datarepresented in RegSim format must be transferred to the data acceptable by MATLAB. Such
conversion is possible using the programme REG2MAT.
2.7.4 Matrix Computation
To demonstrate how matrix computations are used in RegSim, a discrete time Kalman filter
described by the following equations are implemented using RegSim.
xk+1 = xk + uk + Kk (y Cxk)
Regsim 3.8
7/29/2019 regeng
15/60
2.7 Examples of some system descriptions 15
Kk = PkCT
R2 + CPkCT1
Pk+1 = PkT + R1 KkCPk
T
=
1 0 0.40.1 0.8 0.00.2 0 0.8
R1 = 2T
R2 =
The Corresponding RegSim code is given by
DISCRETE SYSTEM Kalman
STATE X tak{
3}
P{
3,3}NEW N X tak{3} N P{3,3}
TSAMP ts
TIME t
Theta : {{1,0,0.4},{0.1,0.8,0},{0.2,0,0.8}}Gamma : {0.2,0.1,1}C : {1,0,1}R1 = Gamma*Gamma*sqr(sigma)
K = Theta*P*C/(R2 + C*P*C)
N X tak = Theta*X tak + Gamma*u + K*( y - C*X tak)
N P = Theta*P*Theta + R1 - K*C*P*Theta
y = adin(0)
ts = t + h
h : 0.2
sigma : 0.2
R2 : 0.5
END
note!
When exporting or importing matrices it is important that the system which exports the matrices
be given first in the compiling list of programmes in COMP. If not the importing programme
would declare the matrix as a scalar, and this will result in an error in the compilation.
Regsim 3.8
7/29/2019 regeng
16/60
Chapter 3
The RegSim Commands
The RegSim is driven by Commands. The commands are either built in in RegSim, for example
AXES, or it can be an alias or a name of an command file. One or more commands can be given
in one line, and the commands are separated by semicolons.
For every built in command there is a Function key that can be used very quickly.
3.1 Notation
Following notation is used in describing a command.
op1 |. . . | opn Defines different options which MUST be given with the command.
[. . . ] Denotes that what is inside the square brackets can be left out.
{...}* A star denotes that what is inside the brackets can be repeated.
value A numerical argument.
name Name of a variable.
filename Name of a file which can be given with the path.
expr Regular expression, e.g. 1+sin(x). Note that a space is considered as a
separator and hence 1 +sin(x) is interpreted as two separate expressions
when two are permitted. However, if only one expression is expected then the
space has no importance. To be on the safe side one can include an expression
within parenthesis.
Regsim 3.8
7/29/2019 regeng
17/60
3.2 How to give arguments 17
3.2 How to give arguments
A number of commands in RegSim can accept one or more arguments, for example one can
write
plot x y
Where x and y are arguments to the command PLOT. The command interpreter in RegSim
uses the space between arguments as a separator. For example if you give
plot x+y
there is one argument given by x+y, and the sum of x and y is plotted. On the other hand if
you give
plot x +y
then there are two arguments x and +y, and two curves, both x and y are plotted. To avoid
this confusion and unexpected results the following two methods can be adopted as precautions.
3.2.1 Method 1
Include the argument within the citation marks. For example
plot "x + y"
The command interpreter take away the citation marks and interpret the above command asequivalent to
plot x+y
3.2.2 Method 2
Include the argument within the parenthesis. For example
plot (x + y)
When there is only one argument expected then the parenthesis has no functionality. It is alsonot necessary to include the whole expression inside the brackets. It is sufficient to include only
the part where the space can be critical. For example
plot ( 5*(4 + sin(x))/(1 + sqr(y)) )
can give the same result as
plot 5*( 4 + sin(x) )/( 1 + sqr(y) )
3.2.3 Options
A option has an argument with two symbols, the first one being the minus-sign. For example
Regsim 3.8
7/29/2019 regeng
18/60
18 The RegSim Commands
simu -c (x > 0)
Here -c is an option and ( x > 0 ) is an argument.
This can leads to problems if one uses a single digit negative number as an argument. Toovercome this problem one can use the method 2 described in the previous subsection. For
example
graph -i 0 (-2) 0 2
draws three strokes at y = 2, y = 0 and y = 2, but
graph -i 0 -2 0 2
draws two strokes at y = 0 and y = 2, in window 2.
Note that the method 1 does not work in this case because the citation sign will be taken away
from the argument.
3.3 History of command given
The a number of the latest RegSim commands given in the command window are automatically
stored in history list in RegSim. One can bring back these commands using the keyboard keys
and .
Regsim 3.8
7/29/2019 regeng
19/60
3.4 The Commands 19
3.4 The Commands
Aritmmetic operations + - * /\
Purpose Aritmmetics for scalars and matrices.
Usage A + BA - B
A * B A .* B
A / B A ./ B
A \ B A .\ BA
Description Works both with scalars and matrices. RegSim has two different types of arith-
metic operations. Matrix arithmetic operations are defined by the rules of linearalgebra. Array arithmetic operations are carried out element-by-element. The
period or decimal point character, ., distinguishes the array operations from the
matrix operations. However, since the matrix and array operation are the same for
addition and subtraction, the character pairs .+ and .- are not used.
+ Addition. A+B adds A and B. A and B must have the same dimensions, unless
one is scalar. A scalar can be added to a matrix of any dimension.
- Subtraction. A-B subtracts B from A. A and B must have the same dimen-
sions, unless one is scalar. A scalar can be subtracted from a matrix of any
dimension.
* Matrix multiplication. A*B is linear algebraic product of the matrices A and
B. The number of columns ofA must equal the numner of rows ofB, unless
one of them is a scalar. A scalar can multiply a matrix of any dimension.
.* Vektor multiplication. A.*B is the element-by-element product of the arrays
A and B. A and B must have the same dimensions, unless one of them is a
scalar.
\ Backslash or matrix left division. If A is a square matrix, A\B is roughlythe same as inv(A)*B, execpt it is computed in a different way. IfA is an
n-by-n matrix and B is a column vector with n components, or a matrix with
severeal such columns, then X=A\B is the solution to the equation AX=Bcomputed by Gaussian elimination.
IfA is an m-by-n matrix with m = n and B is a column vector with m com-ponents, or a matrix with several such columns, then X=A\B is the solutionin least square sence to the under- or overdetermined system of equations
AX=B.
.\ Array left division. A\B is the matrix with elements B(i,j)/A(i,j). Aand B must have the same dimensions, unless one of them is a scalar.
/ Matrix right division. B / A is roughly the same as B*inv(A). More
precisely B/A = ( A\B ).
./ Array right division. A./B is the matrix with elements A(i,j)/B(i,j).
A and B must have the same dimensions, unless one of them is a scalar.
Regsim 3.8
7/29/2019 regeng
20/60
20 The RegSim Commands
A scalar operation ax calculates ax
Matrix transpose. A is the linear algebraic transpose ofA.
absPurpose Absolute value
Usage Y = abs(X)
Description The function abs(X) calculates the absolute value of all elements in the matrix
X.
acos, asin, atanPurpose Inverse trigonometric funcitions
Usage Y = acos(X)
Y = asin(X)
Y = atan(X)
Description Operates element-wise on matrices
adinPurpose Input from an A/D-converter
Usage y = adin(channelnr)
Description This function is useful only if the computer has A/D-converters and RegSim has
the right configuration.
alg
Purpose To choose the integration algorithm.Usage Alg [ ON | OFF ]
Description Currently there are two algorithms that one choose between. One a third or-
der Runge-Kutta (Felhberg) and the other a fifth order (DOPRI). The Felhbergs
method is faster, but some times can leads to instabilities in the step length com-
putation, specially if the system is stiff. The second method handles stiff systems
without much tendencies towards instabilities. However it has difficulties in han-
dling relay and other similar non-linearities.
When RegSim is started it uses the Fehlbergs method, but when given alg on
uses DOPRI-method.
Regsim 3.8
7/29/2019 regeng
21/60
3.4 The Commands 21
aliasPurpose To assign an name to a group of RegSim commands
Usage Alias name commandstring
Description With this command one can define a new command, for example one construct
the command go
>> alias go (axes;init;simu 100)such that each time the command >> gois given the commands axes, init and simu are executed in that order. In principle
any number of alias can be defined. Using the command MAKE all the alias can
be saved in a command file.
arrowPurpose To initiate the functions right, up and pgup
Usage shift F2
Arrow [-c] [-r] [-l] [-u] [-d] [-U] [-D]
Description This command can be used to initialize the functions right, up and pgup to the
desired initial value.
Options -r set right= 1.0
-l set right= 1.0-u set up= 1.0
-d set up= 1.0
-U set pgup= 1.0
-D set pgup= 1.0
-c set all functions= 0.0
atan2Purpose arctangent
Usage a = atan2(y,x)
Description The function atan(y,x) calculates the arctangent for y/x. The result is in
the interval [, ] wich is different from atan(y/x) that has the interval[/2, /2].
Regsim 3.8
7/29/2019 regeng
22/60
22 The RegSim Commands
axesPurpose To draw axes and clear graphic windows
Usage F1Axes [ -1 | -2 | -3 ... ]
Description Draws aexs and clears all or the windows that are in the argument list. If the
scaling of a window is changed, then this window will be cleared irrespective of
what is given in the argument. The scaling is decided by the values that are in the
status routine (see command Scale).
beep
Purpose Gives a beep soundUsage Beep
begPurpose limit function
Usage y = beg(x,xlow,xhigh)
Description The scalar function beg returns max(xlow, min(x, xhigh))
byePurpose Exits Regsim
Usage Bye
calcPurpose Computes simple expressions.
Usage Ctrl F7Calc [expr]
Description Computes and writes the value of an expression.
Example C a l c 1 > 0
Value = TRUE
Calc 2*2 5 - 4
Value = 46
Regsim 3.8
7/29/2019 regeng
23/60
3.4 The Commands 23
cdPurpose To change the working directory
Usage Shift F3cd [dir]
Description Changes to an desired working directory. If cd given without an argument then
the present directory is shown.
Example cd a:
cd ..
cd
clearPurpose To clear a part of the command routine from text
Usage Clear [ rad ]
Description If Clear is given without arguments, then the whole command routine is cleared
and the cursor is placed at the beginning of the first line.
compPurpose To compile those files which describe the process
Usage F9Comp [{filename}*]
Description Compiles the file or files that describe the system that we intend to simulate. Note
that all the files must be named, even the Modula-2 systems that were loaded with
Loadfunc.
If the complier detects an error in the system description, a message will be sent.
If there are a lot of errors, then it will be difficult to find all the errors, and hence
it is suitable to use the command Debug.Using TAB one can call back the previous file list.
companPurpose Creates a companion matrix
Usage A = compan(p)
Description If p is a row vector then compan(p) is a mtarix with the first row equal to
the input vector and with ones in the sub diagonal. If p is a column vector then
compan(p) is a matrix with the first column equal to the input vector and with
ones in the super diagonal.
Regsim 3.8
7/29/2019 regeng
24/60
24 The RegSim Commands
convPurpose Convolution and polynomial multiplication.
Usage c = conv(A,B)
Description With m as the length of the vector A and n as the length of vector B the resulting
vector is length n+m-1 and the elements are
C(k) =j
A(j)B(k + 1 j)
Where the sum is over all j that gives a valid index for A and B.
If A and B are vectors of polynomial coefficients, convolving them is equivalent
to multiplying the two polynomials.
cosPurpose Cosine
Usage Y = cos(X)
Description The function cos(X) returns the cosine of all elements of the matrix X.
dautPurpose Analog output from a D/A-converter
Usage y = daut(channel,x)
Description If the computer has a D/A-converter this function can be used to change the output
of the D/A-converter. The function returns the new voltage.
Se also adin
debugPurpose Send the compilation to the debug mode.
Usage Ctrl F9Debug [ ON | OFF ]
Description Gives some extra information during compilation. If DEBUG is used with com-
piling it gives a list of all the errors or if there are no errors the programme will be
listed in the sorted form.
Regsim 3.8
7/29/2019 regeng
25/60
3.4 The Commands 25
defaultPurpose To give the parameters in command files a value.
Usage name textstring
Description With this command it is possible to make sure that all the formal variables in a
command file have a value.
Example If the command file
MACRO sim3 time value
default time 20
default value 15
par simtid $(time)
par ti[reg] $(value)
init
simu
is called without any argument, then the simulation time is 20 and the parameter
ti[reg] gets the value 15. If the next call is
>> sim3 100then the simulation time becomes 100 and ti[reg] = 15.
definePurpose Defines new global parameters
Usage Define name
Description Used to define new global parameters.
Regsim 3.8
7/29/2019 regeng
26/60
26 The RegSim Commands
delayPurpose Simulation av time delays
Usage y = delay(td,x,t)
Description If you want to simulate a time delay
y(t) = x(t td)
In regsim this can written as
TIME t
y = delay( td, x, t )
td : 0.5
It is also possible to simulate systems of the type
y(t) = y(t td) + u(t)
In Regsim:
CONTINUOUS SYSTEM ex1
INPUT u
TIME t
y = delay(td,y,t) + u
td : 0.34
detPurpose Matrix determinant
Usage d = det(X)
Description det(X) is the determinant of the square matrix X.
diagPurpose Diagonals of a matrix
Usage Y = diag(X)
Description diag(X) is the main diagonal of X.
Regsim 3.8
7/29/2019 regeng
27/60
3.4 The Commands 27
diffPurpose Differanse
Usage Y = diff(X)
Description Diff for a vector
X =
x(1) x(2) . . . x(n)
is x(2) x(1) x(3) x(2) . . . x(n) x(n 1)
diff(X), for a matrix X, is the matrix of column differences.
dirPurpose Lists the files in the working directory
Usage Shift F6Dir [pattern]
Description Gives a list of all the files in the current working directory which matches with the
pattern. Using
dir *.*
give all the files in the directory.
dosPurpose Jumps temporarily to MS-DOS
Usage Alt F5Dos
Description Leaves the control to MS-DOS. To return to RegSim the command EXIT must be
given.
echoPurpose On and off the echo
Usage Shift F8Echo [ ON | OFF ]
Description If the echo is off, then it suppress the text of the command appearing in the com-
mand window when a command file or loops are executed.
If echo is given without an argument then it changes the status and the new status
is written out.
Regsim 3.8
7/29/2019 regeng
28/60
28 The RegSim Commands
editPurpose Starts an editor of your choice.
Usage Ctrl F5Edit [ filename ]
Description The command starts the normal editor Temac if it exists in any of the directories
declared in the MS-DOS variable PATH. If the file name is given as an argument
then the editor reads in that file. At the end of the editing the RegSim takes the
control and one can continue as if before calling the editor.
It is possible to choose another editor other than Temac. This is done by setting the
MS-DOS variable EDITOR equals to the file name where the editor exists. The
simple way to do this is to include the following line in the AUTOEXEC.BAT file.
SET EDITOR = pt.exeor
SET EDITOR = c:\ prog \ emacs.exe
endPurpose The last line in a command loop.
Usage End
Description See Loop and Foreach.
expPurpose Exponential function ex
Usage Y = exp(X)
Description exp(X) is the exponential of the elements of X.
execPurpose To execute a DOS-command
Usage doscommandExec doscommand
Description Used to run another programme from RegSim or to execute a dos command.
exitPurpose End the execution of the RegSim package
Usage Shift F10Exit
Regsim 3.8
7/29/2019 regeng
29/60
3.4 The Commands 29
exitloopPurpose Stop execution of a loop command.
Usage Exitloop
Description See the command loop.
fastPurpose To select among fast or slow plotting.
Usage Fast [ ON | OFF ]
Description When simulating a system which contains both discrete time and continuous sys-
tems, it may be desirable to plot the continuous systems variables even directly
after sampling. The simulation is not affected by this, but only presents the vari-
ables on the screen in a more accurate way. The variables for which it is applicable
is the variables of the continuous time system that are directly depending on the
variables in the discrete time system.
If fast is ON, then the plotting is faster because RegSim does not bother to plot
direct after sampling.
foreachPurpose To create a command loop
Usage Foreach name (argumentlist)
Description Functions quite similar to Loop. The difference is that the number of repetitions
are are decided by the number of elements in the argument list. In each repetition,
the loop variable name gets a new value from the argument list.
The argument list consists of arbitrary number of text strings which are separated
by space. If the space is desired in a text string, then it is included between the
citation sign .
All occurrences of %(name) are supplied with the actual value of loop-variable.
Example Foreach x ( 0 1 x[proc] x2[proc] 5 )
par ztime %(x)
init
simu
end
Regsim 3.8
7/29/2019 regeng
30/60
30 The RegSim Commands
graphPurpose Direct plotting of expressions
Usage Shift F9Graph [ -i nr ] [ -n ] [ -X expr expr ] [ plotoptions ]
Description With graph the functions can be plotted directly. As the independent variable @
can be used. Automatic scaling will be done if mode=A (see command MODE).
Options -i Divides the plotting to nr intervals. More the number of intervals smoother
the curves would be.
When using polygon plotting or box plotting, it is suitable to give the option
-i 0, then the polygon is drawn only once.
-n When this option is given the old interval limits are used. Without option,
the program would ask between which values @ should vary.
-X With this option one can decide between which values the variable @
should vary under plotting.
For more, see PLOT.
Regsim 3.8
7/29/2019 regeng
31/60
3.4 The Commands 31
hcopyPurpose Gives a copy of what is on the plot window of the monitor in a Postscript Laser
printer.
Usage F10Hcopy [ ON | OFF ] [ PS | EPS ] [ -f filename ]
Description With hardcopy active (this is indicated Hcopy(ON) in the bottom left corner) saves
all what is drawn on the screen to a file. A name can be given to the file using
option -f. If one wants to take a copy of the screen the the following command
is given
>> Hcopy PS [-f filename]This produces a file with name filename.PS, which can be sent to a laser writer
which understands Postscript.
With
Hcopy PS [ -f filnamn ]
a Postscript file which can be imported to Lotus Manuscript or Latex can be pro-
duced.
To produce a file one can give the following command sequence
hcopy on
axes
init
simu
hcopy off ps
Or we can create an alias as follows
alias hc (hcopy on;axes;init;simu;hcopy off ps)
This alias can for example be inserted in the file REGSIM.MCR which is read
when RegSim is started. In this way the command is always defined.
Regsim 3.8
7/29/2019 regeng
32/60
32 The RegSim Commands
helpPurpose Give some help
Usage F10Help [ kommando ]
Description Use and see the results.
if-else-endifPurpose If-else construction in the command files.
Usage IF boolean expr ELSIF boolean expr ELSE ENDIF
Description Gives the possibility of conditional execution of command files.
Example IF (x + xtd) > 0.5
scale -x 0 x+xtd
ELSE
scale -x 0 0.5
ENDIF
if-then-else
Purpose Conditional calulation
Usage y = IF boolean expression THEN expr1 ELSE expr2
Description It the boolean expression is true the the value of the expression is expr1, if it is
false then the value is expr2.
expr1 and expr2 must be of the same type and size
Example y = I F x > 0 T H E N 4*t ELSE 45
o p e n = z < 0
dx = IF open THEN{
1,2,0}
ELSE 0.1*
x - u
It is possible to break for a new row after THEN and ELSE
infoPurpose Open or close the information window
Usage Info { off | on }
Description The information window is normally visible to the left of the command window.
Regsim 3.8
7/29/2019 regeng
33/60
3.4 The Commands 33
initPurpose Initializes the state variables etc.
Usage F2Init
Description Initializes the states, output signals etc. This command ought to be used when one
wish to start up a simulation or control with known initial values.
installPurpose Initialize the screen dump in an AT-computer with EGA-graphics
Usage Alt F3Install
Description Before one can do a screen dump from an AT-computer with EGA-graphics, one
must tell which port must be used and at the same time whether a simple or better
quality copies are needed (the better takes twice the time).
intPurpose Conversion to integer
Usage y = int(x)
Description int(x) returns the integer part of x, the result has the type integer.
The function rounds towards zero.
invPurpose Matrix inverse
Usage Y = inv(X)
Description inv(X) is the inverse of the square matrix X.
In practise it is more efficient to use matrix divsion to solve systems of linear
equations. The equation A*x = b has the solution x = inv(A)*b , but it
is more efficient to use the solution x = A\b that uses gauss elimination.
Regsim 3.8
7/29/2019 regeng
34/60
34 The RegSim Commands
listPurpose List the values of the parameters etc.
Usage F4List [ {systemname}* ]
Description This command gives a list of all the state variables, other variables and parameters
along with the values they have at the present time of the simulation. To find the
value of a single variable, the command PAR is recommended.
One can specify variables of which system or systems one likes to have a look.
One of these systems is the Global which contains all global variables, for example
Simtid and Epsilon.
lnPurpose Natural logarithm
Usage Y = ln(X)
Description ln(X) is the natural logarithm of the elements of X
load
Purpose Brings parameter values from a file.
Usage Alt F1Load [ filename ]
Description Brings parameter values and the initial values from a file which has been created
earlier with an text editor or with command Save.
locatePurpose Places the cursor.
Usage Locate [ expr [ expr ] ]
Description Places the cursor at the line and column given by the expressions. The first ex-
pression gives the row(line) and the second expression the column. If any of the
expressions is left out then their values are set to 0.
Regsim 3.8
7/29/2019 regeng
35/60
3.4 The Commands 35
logPurpose Common (base 10) logarithm
Usage Y = log(X)
Description log(X) is the base 10 logarithm of the elements of X
loopPurpose Create a command loop.
Usage Loop
Description A command loop is a group of commands that begins with command Loop and
end with command End. The commands in this loop are executed until the com-
mand Exitloop is executed or the operator press the Esc after getting tired.
An example of a command loop is
define x
par x 10
loop
par ramptid[ramp] 2+x/10
init
simu
par x x+1
i f x = 1 1
exitloop
endif
end
makePurpose Generates a command file.
Usage Make [ filename ]
Description With this command one can save almost all the regsim-environment, scaling, win-
dow sizes, plot commands etc. so that one can create back the same environment
later. Another application is the creation of a skeleton for a command file. For ex-
ample after some experiments with window sizes, scales, parameter changes etc.,
when one is satisfied with all the settings and would like to create a command file
with these settings, the the command Make can be used to generate the desired
file automatically.
Regsim 3.8
7/29/2019 regeng
36/60
36 The RegSim Commands
makefuncPurpose Creates a table function.
Usage Makefunc {filename}*
Description With this command one can create a new function or define a old table function.
The table contains function values for given points. If the function value for a
point in between is needed it is obtained by linear interpolation.
The functions are defined in a file in the following format
[ PERIODIC ] FUNCTION namn
x1, f(x1)
x2, f(x2)
.
.
.
xn, f(xn)
END
The ordering of the data points is not important. The number of points must be
less than 399. If the prefix Periodic is used, then the function becomes periodic
with period = max(x) - min(x).
max, minPurpose Largest or smallest element
Usage y = max(a,b)
y = min(a,b)
Description max(a,b) is the largest element in X.
min(a,b) is the smallest element in X.
See also mmin and mmax.
maxwinPurpose Changes the number of visible windows.
Usage m a x w i n [ 1 | 2 | 3 | 4 ]
Description Decides how many window must be shown on the screen. In this version maxi-
mum of 4 windows can be shown at the same time.
Regsim 3.8
7/29/2019 regeng
37/60
3.4 The Commands 37
meanPurpose Average or mean value
Usage m = mean(X)
Description For vectors, mean(X) is the mean value of the elements in X. For matrices,
mean(X) is a row vector containing the mean value of each column.
medianPurpose Median value
Usage m = median(X)
Description For vectors, median(X) is the median value of the elements in X. For matrices,median(X) is a row vector containing the median value of each column.
memPurpose Give information of the memory.
Usage Mem
Description Tells how much unused memory is left, in terms of number of paragraphs. A
paragraph = 16 byte.
menuPurpose Menu based changing of parameter values.
Usage Shift F7Menu
Description This command is used together with par -m to create menus.
There are two levels. The upper level contains titles which are given using the
command par -m. The second level contains the variables associated with each
title of the upper level. The variable are also given by the command par -m.
Try this
par -m System simtid epsilon flat break
menu
Once menu is invoked (by typing Menu), to select a title using the arrow keys and
pressing ENTER. To leave a menu press Esc. Once the title is invoked the variable
can be selected using the arrow keys again.
Regsim 3.8
7/29/2019 regeng
38/60
38 The RegSim Commands
mmaxPurpose Largest element
Usage Y = mmax(X)
Description For vectors, mmax(X) is the largest element in X. For matrices, mmax(X) is a
row vector containing the maximum element from each column.
mminPurpose Smallest element
Usage Y = mmin(X)
Description For vectors, mmin(X) is the smallest element in X. For matrices, mmin(X) is arow vector containing the minimum element from each column.
modePurpose Changes the mode for scaling of the axes.
Usage shift F5M o d e [ - 1 | - 2 | - 3 | - 4 ] [ - o | - a | - s | - y ]
Description Decides the mode for scaling of the axes with commands Show and Graph. Thecurrent mode is shown in the left bottom of the screen. It can be (.) the old value
is used, (A) automatic scaling, (Y) automatic scaling only for Y-axis or (S) auto-
matic scaling so that the scale factors for both axes are the same.
If the screen is divided into few windows, then we can obtain the status for respec-
tive window. For example (.S.A) means that the window 2 does automatic scaling
etc.
Options -o MODE = (.)
-a Automatic mode, MODE = (A)
-s Automatic mode, MODE = (S)-y Automatic mode, MODE = (Y)
-1 Specifies for which window the changing is valid. If options are left out then
all the windows are included.
Regsim 3.8
7/29/2019 regeng
39/60
3.4 The Commands 39
mshiftPurpose Rowshift of a matrix
Usage Y = mshift( X, U )
Description All rows of the matrix X is shifted one position, and the first row is then replaced
with U.
See also shift.
Example mshift({{1,2,3},{2,4,1},{3,2,7}},{7,8,9})7. 8. 9.
1. 2. 3.
2. 4. 1.
normPurpose Matrix or vector norm
Usage n = norm(X)
Description For a matrix, norm(X) is the largest singular value of X, max(svd(X)).
For a vector, norm(X) = sqrt(sum(X)).
optPurpose Faster simulation
Usage Opt [ ON | OFF ]
Description If Opt is invoked then the RegSim tries do an extra optimization to speed up the
simulation.
palette
Purpose To change the colours.
Usage Palette
Description Gives a possibility to choose the colours of most of the graphic windows and the
curves. The desired colour parameters can be saved in a file REGSIM.INI which
must be in the same directory as REGSIM.EXE.
Regsim 3.8
7/29/2019 regeng
40/60
40 The RegSim Commands
parPurpose To change the parameter values or the initial values.
Usage F7Par [ [ -s ] name [expr] ]
Par -d
Par -m Title {name}*Par -q name
Description Changes or shows the value of a state, variable, parameter etc.
If name is a state or an output, then the initial value can be changed.
If the value is omitted then shows the value of the given variable.
If variables with same name exit in many systems then a menu with all these
variables are shown and one can select the desired one.
This variable can be used with both simulation and control.
Options -m Used to create a menu with name Title and as elements the variables which
follows. See the commando Menu.
-d Take away all the menus. This happens automatically with the compilation
of a new system.
-s Only for state variables. Changes this value instead of the initial value. Use-
ful to simulate impulse disturbances.
pausePurpose Temporary pauseUsage Pause [ text ]
Description Writes out the text TEXT and waits for a press of a key.
Regsim 3.8
7/29/2019 regeng
41/60
3.4 The Commands 41
plot
Purpose Specifies which variables must be plotted under simulation and control.
Usage F6
Plot [-R expr] [-1|-2|-3|-4] [-N | -L | -B] [-r] [-c nr]
[-i nr] [-h text] [-x expr] [{expr}*]
Description Specifies what should be plotted during simulation or control. The parameters are
separated by space.
It is possible to plot many objects in different windows. A object can be of type
Normal, Line, square or box. A new object is created using one of the options
N,L,b,B. A object inherits its colours from the preceding object.During controlling (real time running) the different windows are updated in even
intervals and this interval can be changed with command Plotpar.
Options -c Use colour number nr (0 nr 8) for the curves that will follow. Withthis it is possible to get different colours on different segments in polygon
plotting.
-C Conditional plotting. The option followed by a boolean expression. The
condition is associated with an object. Whether the object would be plotted
or not is decided by the condition. This can be used to take away temporary
contours.-i Use colour number nr to the first curve and nr+1 to the second, etc. If
either the options c or i is given then -i 0 is used.
-F reads in a named file and interpret its content as a parameter. Advantageous
to use when the expression undealably long.
-h Specifies what must be the captions of the curves. If space is desired in the
caption then it must be enclosed with the citation signs .
-r Used in connection with polygon plotting and box plotting, to erase the fig-
ure when a new one is drawn. This is a simple way to do animation.
If used in Normal plotting (-N), then this option works in a different mannerand rolls the window from right to left and the curves continue to be plotted
in the right hand side of the window.
-N New object, Normal plotting. Used for example to end polygon plotting.
-L New object, polygon plotting. The x and y coordinates of two point have to
be given and a straight line connecting these two points are drawn. At least
four arguments have to be given.
-b New object, square plotting. Exactly four arguments have to be given, they
are the coordinates of the two diagonal ends of the square.
-B New object, Box plotting. Exactly four arguments have to be given, they arethe coordinates of the two diagonal ends of the square. The square is filled
with a colour.
Regsim 3.8
7/29/2019 regeng
42/60
42 The RegSim Commands
-x To change the independent variable in Normal plotting.
-R Used in real time plotting. An expression is used to decide when the plotting
can be done.
-1 Selects window 1 etc. Begins also a new object of type Normal.
Example plot x y
Plots variables x and y with respect to time.
Graph -x sin(@) cos(@) -L -c 4 0 0 sin(@) cos(@)
draws a wheel with spokes.
Graph -F figur.1
Reads the figur.1 which can contain
#
7/29/2019 regeng
43/60
3.4 The Commands 43
pgupPurpose Interaction with the user
Usage y = right()
Description This function can return the values -1, 0 and 1 depending on wich of the keys
PGDN, HOME and PGUP has been pressed. With this function it is possible to
give inputs from the keyboard to process
Give the command arrow too use the function during real time control regu.
plotperPurpose Decides the period time for updating different windows used during real time
running.
Usage ctrl F6plotper [ -1 | -2 | -3 | -4 ] [{expr}*]
Description With this command one can change the period time for plotting during the real
time running (see REGU). The period time is given in milli seconds.
One should nod choose too short period times because it lowers down the system
speed. Furthermore one ought to select a period times that are multiples of differ-
ent sampling times used in the system (see initime and regu).
During animation it is suitable to use period time as 50 or 100 ms.
Example plotper 50 100
sets period time for window 1 to 50 ms and for window 2 to 100 ms.
plotper -4 40
sets the period time of window 4 to 40 ms.
pputPurpose Change value on digital output
Usage y = pput(x)
Description Changes the value on the digital output.
printscrPurpose Dumps screens contents to a printer.
Usage Alt F2Printscr
Description It is useful when one needs to do a print screen in a command file
Regsim 3.8
7/29/2019 regeng
44/60
44 The RegSim Commands
qsortPurpose Sortering av element i vaxande ordning
Usage Y = qsort(X)
Description For en vektor sa sorterar qsort(X) elementen i vaxande ordning. For en matris
sa sorterar qsort(X) varje radvektor i vaxande ordning.
quitPurpose Exits regsim
Usage quit
Description See also BYE and EXIT.
Regsim 3.8
7/29/2019 regeng
45/60
3.4 The Commands 45
reguPurpose Start or stops a real time system.
Usage F8Regu
Description Starts a real time running of the discrete time systems. The continuous systems
that are defined become inactive.
Informs that the function simulating() returns the value FALSE
After the real time running has started, one can come back to the command in-
terpreter, and this means that commands can be executed while real time running
continues. For example one can change the size of the window, change scales,
parameters, sampling time etc.
The real time running is handled by a real time kernel which is driven with certain
periodicity (see initime). The period time is decided from the sampling time ofthe discrete systems, plotting period time (see Plotper), data logging period time
(see store) and a internal process with period time of 1 s.
The discrete system has the highest priority because they are executed first and if
there is time left then the logging and plotting is done.
If the discrete systems can not be executed during the given sampling time then
the real time running is stoped. But not if the plotting can not find time in every
period.
For real time running, the sampling time of a discrete system is decided by the
variable SAMPTIME which automatically defined in all discrete systems. SAMP-
TIME is a integer variable with units milliseconds.For not to confront troublesome differences during simulation (where next sam-
pling is decided by a TSAMP-declared variable), the following construction can
be used if one expect to use the system for both simulation and real time running.
DISCRETE SYSTEM test
STATE ......
NEW .......
TIME t
TSAMP ts
INITIAL
samptime = 100
SORT
ts = t + samptime/1000
Regsim 3.8
7/29/2019 regeng
46/60
46 The RegSim Commands
rightPurpose Interaction with the user
Usage y = right()
Description This function can return the values -1, 0 and 1 depending on wich of the keys ,HOME and has been pressed. With this function it is possible to give inputsfrom the keyboard to process
Give the command arrow too use the function during real time control regu.
arrow.
satPurpose Limit function
Usage y = sat(x)
Description The function sat returns a matrix that is a copy of X with all elements limited such
that |yij| 1
Example sat({5,0,-3})1. 0. -1.
sat(2.34)
1.
savePurpose Saves parameter values in a file.
Usage Ctrl F1Save [ filename ]
Description Save all parameters and initial values in a file which can in a later occasion be
read by Load. This file is a pure text file and can be changed as desired. One can
also write ones own file so that in a simple manner can change few parameters at
the same time.The file must have the following format
SYSTEM systemnamn
variablename : numerical value
.
.
END
Regsim 3.8
7/29/2019 regeng
47/60
3.4 The Commands 47
scalePurpose Changes the scale factors of the axes.
Usage F5Scale [ -1 | -2 | -3 | -4 ] [ -x expr expr ] [ -y expr expr
]
Description Changes the scaling. If function in invoked by using F5, the cursor is placed in a
box which appears on the screen.
The cursor can be moved using and .One can also change the scale factors by writing the new value and pressing the
ENTER.
With PGUP and PGDN one can move up and down between the different boxes
corresponding to different windows.
By pressing the Escape (ESC) the box will vanish in the same way as it appeared
and the cursor is back in the command window.
Options -x Changes the scales of the x-axis
-y Changes the scales of the y-axis
-1 Specifies for which window the scaling is valid. If this option is omitted then
the scaling is for the window 1.
setaxesPurpose ON and OFF the axes.
Usage Setaxes [-1|-2|-3|-4] {off | on}*
Description A window can be shown with or without axes. Without axes the effective area
becomes larger.
Example setaxes off on
The window 1 is drawn without axes and window 2 with axes.
setaxes -2 off
Now the window 2 is axisless
setaxes -3 off off
Now window 3 and 4 are axisless.
Regsim 3.8
7/29/2019 regeng
48/60
48 The RegSim Commands
setfilePurpose Use stored data as input
Usage PC : setfile [ -v ] [ -n ] [ filename ]
MAC : setfile filename systemname variablename
Description With Regsim it is possible to save data from simulations and real time control in
a file with the command STORE. Data from a STORE file can be used as a input
in simulation with the help of this command.
Options -v (Verbose) Extra information is written.
-n Use original variable names. Normally the varibales are collected in a vector
with the name x.
Example Suppose that the STORE file measure.str contains data from three A/D-
converters. In this example the three signals are LP-filtered with regsim
The system file should look like this
CONTINUOUS SYSTEM filter
DER dy{3}STATE y{3}dx = ( x[measure] - y ) / T
T : 0.2
END
Give this commands to run the filter
setfile measure
comp file filter
plot x y
simu
Observere the extra argument file to the command comp.
Regsim 3.8
7/29/2019 regeng
49/60
3.4 The Commands 49
setsizePurpose Changes the dimensions of the windows
Usage Setsize [ -1 | -2 | -3 | -4 ] [ -x expr expr ] [ -y exprexpr ]
Description Changes the dimensions. If the function is invoked without arguments the the
cursor is placed in a box which appears on the screen.
The cursor can be moved using and .One can also change the dimension by writing the new value and pressing the
ENTER.
With PGUP and PGDN one can move up and down between the different boxes
corresponding to different windows.
By pressing the Escape (ESC) the box will vanish in the same way as it appeared
and the cursor is back in the command window.
The constraints for x and y are
0 x 80 , 0 y 20
Options -x Changes the window length
-y Changes the window height
-1 specifies for which window the dimension is valid. Of the option is omitted
then the dimensions of the window 1 is changed.
shiftPurpose Shifts the elements in a Skift av element i en vektor eller matris
Usage Y = shift( X, u )
Description All elements in X is shifted on position and the first elements is replaced with tha
scalar u.
See also mshift.
Example shift({1,2,3},4)
4. 1. 2.
Regsim 3.8
7/29/2019 regeng
50/60
50 The RegSim Commands
showPurpose Plots the saved variables.
Usage Shift F4Show [ -f filename ] [ see options in Plot ]
Description Plots variables which are stored in a file. Functions same as the Plot and Graph.
The scaling of the axes can be automatic (see command Mode). The storing in a
file is done with the command Store.
If option -f is omitted, it questions after the file that the variables have to be
taken.
The command uses files that have the extension .STR.
signPurpose Sign function
Usage Y = sign(X)
Description sign(X) returns the sign of the argument.
Example sign({45,0,-3.23,0.12})1. 0. -1. 1.
Regsim 3.8
7/29/2019 regeng
51/60
3.4 The Commands 51
simuPurpose Simulates
Usage F3Simu [ expr ] [ -b value ] [ -s value ] [ -c expr ]
Description Starts a new simulation or continues a simulation which has been interrupted.
A simulation can be interrupted using Esc. The simulation time is decided by the
global parameter SIMTID which can be changed with command PAR or by giving
the new simulation time as an argument to the command.
simu 20
Changes the simulation time to 20.
To be sure that the simulation starts with the correct initial values for the statesand parameters, the command INIT can be given before simulation. This is not
applicable if one continues a interrupted simulation.
The function Simulating gets the value TRUE.
Options -b Interrupts the simulation after value time units.
-c If the expression becomes true the simulation is interrupted immediately.
Note that the expression can not be controlled continuously.
-s Uses the value as the largest permitted step length. By default, 1/100 ofthe SIMTID (simulation time) is taken.
simulatingPurpose Indication that simulation is running.
Usage b = simulating()
x = IF simulating() THEN y ELSE adin(0)
Description This function returns true if a simulation is running with the command simu and
it is false if real time control is started with the command regu.
sinPurpose Sine
Usage Y = sin(X)
Description sin(X) is the sine of the elements of X.
Regsim 3.8
7/29/2019 regeng
52/60
52 The RegSim Commands
solvePurpose Solution of systems of linear equations
Usage x = solve(A,b)
Description A system of linear equations A*x = b has the solution x = solve(A,b).
This is equivalent with the solution x = A\b.
sqrPurpose Square
Usage Y = sqr(X)
Description sqr(X) is the square of all elements in. For a scalar this is y = x2.
sqrtPurpose Square root
Usage Y = sqrt(X)
Description sqrt(X) is the square root of the elements of X.
storePurpose Specifies which variables must be stored in a file.
Usage Shift F1Store [ -l ] [ -c expr ] [ -p period ] [ -f filename ] [
{name}* ]
Description Specifies which variables has to be stored in a file during simulation or regulation.
Parameters are separated by space and ends with Return.
If the command is started without argument it asks for a file name. One can call
back the old parameter list with TAB-command.
Options -f If option -f is omitted it asks for the file that has to be used.
-c If this option is used the variables are stored only when the condition expr
is TRUE. This option does not mean that one can save more often than when
this condition.
-l Lists which file is used and which variables have to be saved.
-p If this option is used the variables are saved with a time space of period.
This is equivalent to sampling of the variable with period period. If this
option is omitted or the period is too small, the the variables are stored
only if there is a change in the variables. For continuous system this means
the data is stored in irregular intervals.
Regsim 3.8
7/29/2019 regeng
53/60
3.4 The Commands 53
sumPurpose Sum of elements
Usage y = sum(X)
Description For vectors, sum(X) is the sum of the elements of X. For matrices, sum(X) is a
row vector with the sum over each column.
svdPurpose Singular value decomposition
Usage s = svd(X)
Description svd(X) returns a vector containing the singular values, sorted in decreasing or-der.
textPurpose To write text in the graphic window.
Usage Text [ -c nr ] [ -1 | -2 | -3 | -4 ] expr expr "text"
Description Writes the text text at the left bottom end of the first letter at the position which
is defined by the two expressions where the first is the x coordinate and the second
is the y coordinate.The position is given with scaled coordinates.
Options -c Gives the text the colour nr
-1 Defines in which window the text must be written.
timePurpose Measuring time
Usage Time
Description A timer is started every odd time the command is given. The timer is stopped and
the elapsed time is written in the command window every even time the command
is given.
Regsim 3.8
7/29/2019 regeng
54/60
54 The RegSim Commands
toeplitzPurpose Toeplitz matrix
Usage T = toeplitz(C)
Description toeplitz is a symmetric (or Hermitian) Toeplitz matrix
Example toeplitz(1,2,3,4)1. 2. 3. 4.
2. 1. 2. 3.
3. 2. 1. 2.
4. 3. 2. 1.
tracePurpose Sum of diagonal elements
Usage T = trace(X)
Description trace(X) is the sum of the diagonal elements of X, which is also the sum of the
eigenvalues of X.
transfPurpose Transfer function
Usage y = transf( numerator, denominator, u )
Description Use this function to implement a transfer function from the input u to the output
y, both in continuous and time-discrete systems. One limitation is that the transfer
function must be strictly proper.
Example Too simulate the continuous system
Y(s) =as + 1
s2
+ 3 T s + w2
U(s)
in regsim, write
y = transf( { a, 1}, {1,3*T,w2}, u )
where a, T, w and u are parameters or variables defined elsewhere.
Regsim 3.8
7/29/2019 regeng
55/60
3.4 The Commands 55
trapPurpose To tell which computations are not allowed.
Usage Trap [-a] [-i] [-d] [-u] [-o] [-z] [-a]
Description Tells which computations are permitted. If an unpermitted computation is en-
countered it stops simulation or control and the computation that is not allowed is
shown in a box on the screen.
Options -i Undefined numbers, e.g. 0/0. If it is allowed then it gets the valueNAN(Not A Number).
-d Unnormalized number. That is number which is too small to be represented
in a normal way.
-u Underflow, a small number which is set to = 0-o Overflow, a large number which is set ti =
-z Division by zero. The result is =
-a all
truncPurpose Truncate
Usage Y = trunc(X)
Description trunc(X) is the integer part of the elements in X.
upPurpose Interaction with the user
Usage y = up()
Description This function can return the values -1, 0 and 1 depending on wich of the keys ,HOME och has been pressed. With this function it is possible to give inputsfrom the keyboard to process
Give the command arrow too use the function during real time control regu.
arrow.
Regsim 3.8
7/29/2019 regeng
56/60
56 The RegSim Commands
writePurpose To write text in command routines.
Usage Write textstring
Description Used to write out a text string in command routine. Special letters are
\n Change of line in write out.\abc Write out special character CHR(abc) where abc is a three digit decimalnumber.
writeexpPurpose Write out the value of an expression
Usage Writeexp expr
Description This command functions same as the Calc, but the write out is savable so that it
can go with the Write command. The belief is that it can be used in command
files.
Example clear 1
write linelength =
writeexp line[tralla]
write [m]
Regsim 3.8
7/29/2019 regeng
57/60
Chapter 4
Command Files
Command files are a way of creating ones own commands. To define a command file the first
line in the file must contain the following line
MACRO macroname [parametername *]
this can be followed by arbitrary number of commands, one in each line. If a line begins with
the sign # the the whole line is defined as a comment. This sign be placed any where in the
file even before the MACRO-definition.
To use the parameters in a command file one writes $ (parametername) .
Command file must be in a file with name macroname.MCR.
An example of an command file
MACRO komp reg start stop count
echo off
#
default reg pidreg
default start 1.0
default stop 5.0
default count 10
#
define cdefine kk
define step
p a r c 0
par kk $(start)
par step ($(stop)-$(start))/($(count)-1)
#
clear
write regulator = $(reg)
comp tank.con $(reg).con
loop
#clear 1
write k =
Regsim 3.8
7/29/2019 regeng
58/60
58 Command Files
writeexp kk
#
par k kk
init
simu
par c c+1
par kk kk+step
if c=$(count)
exitloop
endif
end
4.1 Invoking by a MACRO
To use a command file it be in the working directory or in a directory which is enumerated in
variable MACRO. This can be set using the MSDOS command SET, for example,
set MACRO = c:\macro
A command file is used by writing the name and the necessary arguments. If the arguments are
omitted then they become blank if there are no default command. For example if we use the
command file komp with count = 15 and the rest of the arguments come from default. This
can be done in two ways,
komp pidreg 1.0 5.0 15
or
komp count=15
Regsim 3.8
7/29/2019 regeng
59/60
Chapter 5
The Syntax for Expressions
The following is the description of the syntex for RegSim in Bakus-Naur form.
variable assignment ::= variable identifier = expression
parameter assignment ::= identifier : constant
| identifier : vector constant []
| identifier : matrix constant
expression ::= relation and relation
| relation or relation
| IF relation THEN relation ELSE expression
| matrix expression
relation ::= simple expression [ relational operator simple expression ]
simple expression ::= [ unary operator ] term adding operator term
matrix expression ::= {vector expression , vector expression}
vector expression ::= {expression , expression}
term ::= factor multiplying operator factor
factor ::= secondary
| secondary
| secondary secondary
secondary ::= [ NOT ] primary
primary ::= constant
| variable identifier
| identifier ( expression , expression )
| ( expression )| matrix constant
Regsim 3.8
7/29/2019 regeng
60/60
60 The Syntax for Expressions
unary operator ::= + | -
adding operator ::= unary operator
multiplying operator ::= * | /| .* | ./| \
relation operator ::= < | > | =
constant ::= number | real
number ::= digit digit
real ::= number . [number] [ exponent ]
exponent ::= E [ - | + ] number
variable identifier ::= identifier| identifier{number , number}| identifier[ identifier ]
| identifier{number , number}[ identifier ]
identifier ::= letter [ letter | underscore | digit | . ]
matrix constant ::= {vector constant,vector constant}
vector constant ::= {constant ,constant}