Sie sind auf Seite 1von 60

RegSim

MANUAL

Thomas Gustafsson October 2003

Contents
1 2 Introduction Model Language 2.1 Introductory Example . . . . . . . . . . . 2.2 Denition of Name and Type of Systems . 2.3 Denition of Special Variables . . . . . . 2.3.1 Global Variables . . . . . . . . . 2.4 Initial values for states and outputs . . . . 2.5 Describing the process mathematically . . 2.6 Combining Different Systems . . . . . . 2.6.1 Connecting System . . . . . . . . 2.6.2 Without connecting system . . . . 2.7 Examples of some system descriptions . . 2.7.1 Second order differential equation 2.7.2 Third order differential equation . 2.7.3 Data acquisition . . . . . . . . . 2.7.4 Matrix Computation . . . . . . . The RegSim Commands 3.1 Notation . . . . . . . . . . 3.2 How to give arguments . . 3.2.1 Method 1 . . . . . 3.2.2 Method 2 . . . . . 3.2.3 Options . . . . . . 3.3 History of command given 3.4 The Commands . . . . . . 3 4 4 6 6 7 9 10 10 11 11 11 11 13 14 14 16 16 17 17 17 17 18 19 57 58 59

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

Command Files 4.1 Invoking by a MACRO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Syntax for Expressions

Regsim 3.8

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. These systems 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 for animation.

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 denitely experience how the rst 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

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 Systems. A RegSim programme to simulate a large process can be in one le or it can be divided in to subsystems, and each can be implemented in different les. Each of these RegSim les 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 rst 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 is
CONTINUOUS 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 dx = 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 le rst.t, then to simulate it we must rst 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

2.1 Introductory Example

and then give the command REGSIM. Once the REGSIM is invoked and the cursor >> appearers 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 gure 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

Model Language

2.2

Denition of Name and Type of Systems

A system can either be a continuous or a discrete time system. The rst line of the RegSim program indicates this. CONTINUOUS SYSTEM <namn> or DISCRETE SYSTEM <namn> There is also a third type known as the CONNECTING SYSTEM and is described in section 2.6.

2.3

Denition of Special Variables

A variable is classied 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 <type> <variablename> ... where <type> 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 MOTOR STATE x y DER dx omega
Regsim 3.8

2.3 Denition of Special Variables

then x and y are states, dx and omega their derivatives, i.e dx = x and omega = 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) and c(t + h) = qw(t). From this one understands that the states z and c cannot be given 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 realtime control do something like this
TSAMP ts TIME 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 Denes how long the simulation has to be done (Simulation Time). The simulation 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

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 dene how accurate the simulation must be. The normal value is = 104 , and this means that the absolute value of the mean value of the state 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 milliseconds 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

2.4 Initial values for states and outputs

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. If values 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} y OUTPUT 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

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 rst of them describes how the value of a variable could be computed while the other denes a parameter. The difference is that a parameter normally has a xed 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. If this is done, the sorting of the expressions can not be done by RegSim. During sorting the different expressions are also classied in the following manner, Time invariant, Derivative computation, Continuous and Time Discrete. Such classication 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 gure 2.2. ref - - Regulator 
6

u Process Givare


y
-

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 dene a complete feedback control system. This can be done in two ways.
Regsim 3.8

2.7 Examples of some system descriptions

11

2.6.1

Connecting System

The rst approach uses an additional system, the so called CONNECTING SYSTEM, where all the couplings are specied. In our example it looks as follows,
CONTINUOUS SYSTEM reg INPUT e OUTPUT u u = ....... END CONTINUOUS SYSTEM givare INPUT y OUTPUT yg yg = ....... END CONTINUOUS SYSTEM process INPUT u OUTPUT y y = ....... 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 using 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. varaiblename[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 givare OUTPUT yg y = y[process] yg = ....... END CONTINUOUS SYSTEM process OUTPUT y u = u[reg] y = ....... END

2.7
2.7.1

Examples of some system descriptions


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

12

Model Language

We want to nd (plot) the phase curves, i.e. x vs x for different initial values. To do this the second order system is rst described as two rst order differential equations by dening the following two state variables, x1 = x x2 = x The the van der Pole equation can be written in two rst order differential equations as follows, x 1 = x2 x 2 = (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 gure 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 gure 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

2.7 Examples of some system descriptions

13

par par par par par par par par par

x1 x1 x1 x1 x1 x1 x1 x1 x1

-2;init;simu 3;init;simu -5;par x2 0;init;simu -0.01;init;simu 0.01;init;simu 5;init;simu -3;par x2 -5;init;simu 2;init;simu 3;init;simu

2.7.2

Third order differential equation

The third order linear differential equation is given by d3 y d2 y dy + a + a2 + a3 y = Ku 1 3 2 dt dt dt This third order differential equation can by described by three rst order differential equation as follows by dening the state variables x1 = y, x2 = dx1 /dt and x3 = dx2 /dt. dx1 = x2 dt dx2 = x3 dt dx3 = Ku a1 x3 a2 x2 a3 x1 dt 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 t dx1=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 rst order differential equations in the same as given in this example.
Regsim 3.8

14

Model Language

2.7.3

Data acquisition

This example shows how a measurement from the real world e.g. water level, voltage, temperature etc., can be obtained provided that the appropriate interface facilities are provided. Also note 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 le dacc.t, the following MACRO (daccqui.mcr) can be used.
MACRO daccqui period filename "lename - name of a le 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 le echo 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 data represented 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 lter described by the following equations are implemented using RegSim.

x k+1 = xk + uk + Kk (y C x k )
Regsim 3.8

2.7 Examples of some system descriptions


1

15

Kk = Pk C T R2 + CPk C T

Pk+1 = Pk T + R1 Kk CPk T 1 0 0.4 = 0.1 0.8 0.0 0.2 0 0.8 R1 = 2 T 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 rst 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

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 le. 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 Denes 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. lename Name of a le 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

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 as equivalent 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 also not necessary to include the whole expression inside the brackets. It is sufcient 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 rst one being the minus-sign. For example
Regsim 3.8

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. To overcome 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

3.4 The Commands

19

3.4

The Commands

Aritmmetic operations + - * / \
Purpose Aritmmetics for scalars and matrices. Usage A + B
A A * A / A \ A B B B B A .* B A ./ B A .\ B

Description Works both with scalars and matrices. RegSim has two different types of arithmetic operations. Matrix arithmetic operations are dened by the rules of linear algebra. 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 dimensions, 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 of A must equal the numner of rows of B, 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 roughly the same as inv(A)*B, execpt it is computed in a different way. If A 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=B computed by Gaussian elimination. If A is an m-by-n matrix with m = n and B is a column vector with m components, or a matrix with several such columns, then X=A\B is the solution in 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). A and 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

20 A scalar operation ax calculates ax

The RegSim Commands

Matrix transpose. A is the linear algebraic transpose of A.

abs
Purpose Absolute value Usage Y = abs(X) Description The function abs(X) calculates the absolute value of all elements in the matrix X.

acos, asin, atan


Purpose Inverse trigonometric funcitions Usage Y = acos(X)
Y = asin(X) Y = atan(X)

Description Operates element-wise on matrices

adin
Purpose 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 conguration.

alg
Purpose To choose the integration algorithm. Usage Alg [ ON | OFF ] Description Currently there are two algorithms that one choose between. One a third order Runge-Kutta (Felhberg) and the other a fth order (DOPRI). The Felhbergs method is faster, but some times can leads to instabilities in the step length computation, specially if the system is stiff. The second method handles stiff systems without much tendencies towards instabilities. However it has difculties in handling 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

3.4 The Commands

21

alias
Purpose To assign an name to a group of RegSim commands Usage Alias name commandstring Description With this command one can dene a new command, for example one construct the command go >> alias go (axes;init;simu 100) such that each time the command >> go is given the commands axes, init and simu are executed in that order. In principle any number of alias can be dened. Using the command MAKE all the alias can be saved in a command le.

arrow
Purpose 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

atan2
Purpose 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

22

The RegSim Commands

axes
Purpose To draw axes and clear graphic windows Usage F1
Axes [ -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 sound Usage Beep

beg
Purpose limit function Usage y = beg(x,xlow,xhigh) Description The scalar function beg returns max(xlow, min(x, xhigh))

bye
Purpose Exits Regsim Usage Bye

calc
Purpose Computes simple expressions. Usage Ctrl F7
Calc [expr]

Description Computes and writes the value of an expression. Example


Calc 1 > 0

Value = TRUE
Calc 2*25 - 4

Value = 46

Regsim 3.8

3.4 The Commands

23

cd
Purpose To change the working directory Usage Shift F3
cd [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

clear
Purpose 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 rst line.

comp
Purpose To compile those les which describe the process Usage F9
Comp [{filename}*]

Description Compiles the le or les that describe the system that we intend to simulate. Note that all the les 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 difcult to nd all the errors, and hence it is suitable to use the command Debug. Using TAB one can call back the previous le list.

compan
Purpose Creates a companion matrix Usage A = compan(p) Description If p is a row vector then compan(p) is a mtarix with the rst 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 rst column equal to the input vector and with ones in the super diagonal.
Regsim 3.8

24

The RegSim Commands

conv
Purpose 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 coefcients, convolving them is equivalent to multiplying the two polynomials.

cos
Purpose Cosine Usage Y = cos(X) Description The function cos(X) returns the cosine of all elements of the matrix X.

daut
Purpose 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

debug
Purpose Send the compilation to the debug mode. Usage Ctrl F9
Debug [ ON | OFF ]

Description Gives some extra information during compilation. If DEBUG is used with compiling 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

3.4 The Commands

25

default
Purpose To give the parameters in command les a value. Usage name textstring Description With this command it is possible to make sure that all the formal variables in a command le have a value. Example If the command le
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 100 then the simulation time becomes 100 and ti[reg] = 15.

dene
Purpose Denes new global parameters Usage Define name Description Used to dene new global parameters.

Regsim 3.8

26

The RegSim Commands

delay
Purpose 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

det
Purpose Matrix determinant Usage d = det(X) Description det(X) is the determinant of the square matrix X.

diag
Purpose Diagonals of a matrix Usage Y = diag(X) Description diag(X) is the main diagonal of X.

Regsim 3.8

3.4 The Commands

27

diff
Purpose Differanse Usage Y = diff(X) Description Diff for a vector X= 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. x(1) x(2) . . . x(n)

dir
Purpose Lists the les in the working directory Usage Shift F6
Dir [pattern]

Description Gives a list of all the les in the current working directory which matches with the pattern. Using
dir *.*

give all the les in the directory.

dos
Purpose Jumps temporarily to MS-DOS Usage Alt F5
Dos

Description Leaves the control to MS-DOS. To return to RegSim the command EXIT must be given.

echo
Purpose On and off the echo Usage Shift F8
Echo [ ON | OFF ]

Description If the echo is off, then it suppress the text of the command appearing in the command window when a command le 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

28

The RegSim Commands

edit
Purpose Starts an editor of your choice. Usage Ctrl F5
Edit [ 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 le name is given as an argument then the editor reads in that le. 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 le name where the editor exists. The simple way to do this is to include the following line in the AUTOEXEC.BAT le. SET EDITOR = pt.exe or SET EDITOR = c:\ prog \ emacs.exe

end
Purpose The last line in a command loop. Usage End Description See Loop and Foreach.

exp
Purpose Exponential function ex Usage Y = exp(X) Description exp(X) is the exponential of the elements of X.

exec
Purpose To execute a DOS-command Usage doscommand
Exec doscommand

Description Used to run another programme from RegSim or to execute a dos command.

exit
Purpose End the execution of the RegSim package Usage Shift F10
Exit
Regsim 3.8

3.4 The Commands

29

exitloop
Purpose Stop execution of a loop command. Usage Exitloop Description See the command loop.

fast
Purpose To select among fast or slow plotting. Usage Fast [ ON | OFF ] Description When simulating a system which contains both discrete time and continuous systems, 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 variables 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.

foreach
Purpose 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

30

The RegSim Commands

graph
Purpose Direct plotting of expressions Usage Shift F9
Graph [ -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

3.4 The Commands

31

hcopy
Purpose Gives a copy of what is on the plot window of the monitor in a Postscript Laser printer. Usage F10
Hcopy [ 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 le. A name can be given to the le using option -f. If one wants to take a copy of the screen the the following command is given >> Hcopy PS [-f lename] This produces a le with name lename.PS, which can be sent to a laser writer which understands Postscript. With
Hcopy PS [ -f filnamn ]

a Postscript le which can be imported to Lotus Manuscript or Latex can be produced. To produce a le 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 le REGSIM.MCR which is read when RegSim is started. In this way the command is always dened.

Regsim 3.8

32

The RegSim Commands

help
Purpose Give some help Usage F10
Help [ kommando ]

Description Use and see the results.

if-else-endif
Purpose If-else construction in the command les. Usage IF boolean expr ELSIF boolean expr ELSE ENDIF Description Gives the possibility of conditional execution of command les. 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 = IF x > 0 THEN 4*t ELSE 45 open = 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

info
Purpose 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

3.4 The Commands

33

init
Purpose Initializes the state variables etc. Usage F2
Init

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.

install
Purpose Initialize the screen dump in an AT-computer with EGA-graphics Usage Alt F3
Install

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).

int
Purpose 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.

inv
Purpose Matrix inverse Usage Y = inv(X) Description inv(X) is the inverse of the square matrix X. In practise it is more efcient 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 efcient to use the solution x = A\b that uses gauss elimination.

Regsim 3.8

34

The RegSim Commands

list
Purpose List the values of the parameters etc. Usage F4
List [ {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 nd 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.

ln
Purpose 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 le. Usage Alt F1
Load [ filename ]

Description Brings parameter values and the initial values from a le which has been created earlier with an text editor or with command Save.

locate
Purpose Places the cursor. Usage Locate [ expr [ expr ] ] Description Places the cursor at the line and column given by the expressions. The rst expression 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

3.4 The Commands

35

log
Purpose Common (base 10) logarithm Usage Y = log(X) Description log(X) is the base 10 logarithm of the elements of X

loop
Purpose 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 command 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 if x = 11 exitloop endif end

make
Purpose Generates a command le. Usage Make [ filename ] Description With this command one can save almost all the regsim-environment, scaling, window 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 le. For example after some experiments with window sizes, scales, parameter changes etc., when one is satised with all the settings and would like to create a command le with these settings, the the command Make can be used to generate the desired le automatically.

Regsim 3.8

36

The RegSim Commands

makefunc
Purpose Creates a table function. Usage Makefunc {filename}* Description With this command one can create a new function or dene 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 dened in a le 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 prex Periodic is used, then the function becomes periodic with period = max(x) - min(x).

max, min
Purpose 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.

maxwin
Purpose Changes the number of visible windows. Usage maxwin [ 1 | 2 | 3 | 4 ] Description Decides how many window must be shown on the screen. In this version maximum of 4 windows can be shown at the same time.

Regsim 3.8

3.4 The Commands

37

mean
Purpose 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.

median
Purpose 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.

mem
Purpose 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.

menu
Purpose Menu based changing of parameter values. Usage Shift F7
Menu

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

38

The RegSim Commands

mmax
Purpose 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.

mmin
Purpose Smallest element Usage Y = mmin(X) Description For vectors, mmin(X) is the smallest element in X. For matrices, mmin(X) is a row vector containing the minimum element from each column.

mode
Purpose Changes the mode for scaling of the axes. Usage shift F5
Mode [ -1 | -2 | -3 | -4 ] [ -o | -a | -s | -y ]

Description Decides the mode for scaling of the axes with commands Show and Graph. The current 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) automatic 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 respective 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 Species for which window the changing is valid. If options are left out then all the windows are included.

Regsim 3.8

3.4 The Commands

39

mshift
Purpose Rowshift of a matrix Usage Y = mshift( X, U ) Description All rows of the matrix X is shifted one position, and the rst row is then replaced with U. See also shift. Example mshift({{1,2,3},{2,4,1},{3,2,7}},{7,8,9})
7. 1. 2. 8. 2. 4. 9. 3. 1.

norm
Purpose 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)).

opt
Purpose 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 le REGSIM.INI which must be in the same directory as REGSIM.EXE.

Regsim 3.8

40

The RegSim Commands

par
Purpose To change the parameter values or the initial values. Usage F7
Par Par Par Par [ [ -s ] name [expr] ] -d -m Title {name}* -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. Useful to simulate impulse disturbances.

pause
Purpose Temporary pause Usage Pause [ text ] Description Writes out the text TEXT and waits for a press of a key.

Regsim 3.8

3.4 The Commands

41

plot
Purpose Species 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 Species 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. With this 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 rst 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 le and interpret its content as a parameter. Advantageous to use when the expression undealably long. -h Species 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 gure 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 manner and 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 are the coordinates of the two diagonal ends of the square. The square is lled with a colour.
Regsim 3.8

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 gur.1 which can contain


# <--- A sign that precede comments # Plot file to draw a wheel with spokes # draw the wheel -N -x sin(@) cos(@) # Draw spokes -L -c 4 0 0 sin(@) cos(@) plot -R tid y[proc] u[reg]

If option R is there then RegSim synchronizes the plotting with real time.
plot x y -r

plots variable x and y against time in a window that continuously moves from right to left so that the current plot can always be seen. Is useful when running in real time and we are only interested in knowing what happened in the near past.

Regsim 3.8

3.4 The Commands

43

pgup
Purpose 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.

plotper
Purpose Decides the period time for updating different windows used during real time running. Usage ctrl F6
plotper [ -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 different 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.

pput
Purpose Change value on digital output Usage y = pput(x) Description Changes the value on the digital output.

printscr
Purpose Dumps screens contents to a printer. Usage Alt F2
Printscr

Description It is useful when one needs to do a print screen in a command le

Regsim 3.8

44

The RegSim Commands

qsort
Purpose Sortering av element i v axande ordning Usage Y = qsort(X) Description F or en vektor s a sorterar qsort(X) elementen i v axande ordning. F or en matris s a sorterar qsort(X) varje radvektor i v axande ordning.

quit
Purpose Exits regsim Usage quit Description See also BYE and EXIT.

Regsim 3.8

3.4 The Commands

45

regu
Purpose Start or stops a real time system. Usage F8
Regu

Description Starts a real time running of the discrete time systems. The continuous systems that are dened 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 interpreter, 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 of the 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 rst 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 nd time in every period. For real time running, the sampling time of a discrete system is decided by the variable SAMPTIME which automatically dened in all discrete systems. SAMPTIME is a integer variable with units milliseconds. For not to confront troublesome differences during simulation (where next sampling 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

46

The RegSim Commands

right
Purpose 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 inputs from the keyboard to process Give the command arrow too use the function during real time control regu. arrow.

sat
Purpose 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.

save
Purpose Saves parameter values in a le. Usage Ctrl F1
Save [ filename ]

Description Save all parameters and initial values in a le which can in a later occasion be read by Load. This le is a pure text le and can be changed as desired. One can also write ones own le so that in a simple manner can change few parameters at the same time. The le must have the following format
SYSTEM systemnamn variablename : numerical value . . END

Regsim 3.8

3.4 The Commands

47

scale
Purpose Changes the scale factors of the axes. Usage F5
Scale [ -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 Species for which window the scaling is valid. If this option is omitted then the scaling is for the window 1.

setaxes
Purpose 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

48

The RegSim Commands

setle
Purpose 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 le with the command STORE. Data from a STORE le 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 le measure.str contains data from three A/Dconverters. In this example the three signals are LP-ltered with regsim The system le 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 lter


setfile measure comp file filter plot x y simu

Observere the extra argument le to the command comp.

Regsim 3.8

3.4 The Commands

49

setsize
Purpose Changes the dimensions of the windows Usage Setsize [ -1 | -2 | -3 | -4 ] [ -x expr expr ] [ -y expr
expr ]

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 species for which window the dimension is valid. Of the option is omitted then the dimensions of the window 1 is changed.

shift
Purpose 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 rst elements is replaced with tha scalar u. See also mshift. Example shift({1,2,3},4)
4. 1. 2.

Regsim 3.8

50

The RegSim Commands

show
Purpose Plots the saved variables. Usage Shift F4
Show [ -f filename ] [ see options in Plot ]

Description Plots variables which are stored in a le. Functions same as the Plot and Graph. The scaling of the axes can be automatic (see command Mode). The storing in a le is done with the command Store. If option -f is omitted, it questions after the le that the variables have to be taken. The command uses les that have the extension .STR.

sign
Purpose 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

3.4 The Commands

51

simu
Purpose Simulates Usage F3
Simu [ 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 states and 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 of the SIMTID (simulation time) is taken.

simulating
Purpose 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.

sin
Purpose Sine Usage Y = sin(X) Description sin(X) is the sine of the elements of X.

Regsim 3.8

52

The RegSim Commands

solve
Purpose 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.

sqr
Purpose Square Usage Y = sqr(X) Description sqr(X) is the square of all elements in. For a scalar this is y = x2.

sqrt
Purpose Square root Usage Y = sqrt(X) Description sqrt(X) is the square root of the elements of X.

store
Purpose Species which variables must be stored in a le. Usage Shift F1
Store [ -l ] [ -c expr ] [ -p period ] [ -f filename ] [ {name}* ]

Description Species which variables has to be stored in a le during simulation or regulation. Parameters are separated by space and ends with Return. If the command is started without argument it asks for a le name. One can call back the old parameter list with TAB-command. Options -f If option -f is omitted it asks for the le 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 le 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

3.4 The Commands

53

sum
Purpose 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.

svd
Purpose Singular value decomposition Usage s = svd(X) Description svd(X) returns a vector containing the singular values, sorted in decreasing order.

text
Purpose 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 rst letter at the position which is dened by the two expressions where the rst 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 Denes in which window the text must be written.

time
Purpose 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

54

The RegSim Commands

toeplitz
Purpose 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.

trace
Purpose 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.

transf
Purpose 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) = in regsim, write
y = transf( { a, 1}, {1,3*T,w2}, u )

s2

as + 1 U ( s) + 3 T s + w2

where a, T, w and u are parameters or variables dened elsewhere.

Regsim 3.8

3.4 The Commands

55

trap
Purpose 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 encountered it stops simulation or control and the computation that is not allowed is shown in a box on the screen. Options -i Undened numbers, e.g. NAN(Not A Number). 0/0. If it is allowed then it gets the value

-d Unnormalized number. That is number which is too small to be represented in a normal way. -u Underow, a small number which is set to = 0 -o Overow, a large number which is set ti = -z Division by zero. The result is = -a all

trunc
Purpose Truncate Usage Y = trunc(X) Description trunc(X) is the integer part of the elements in X.

up
Purpose 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 inputs from the keyboard to process Give the command arrow too use the function during real time control regu. arrow.

Regsim 3.8

56

The RegSim Commands

write
Purpose 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 decimal number.

writeexp
Purpose 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 les. Example
clear 1 write linelength = writeexp line[tralla] write [m]

Regsim 3.8

Chapter 4 Command Files


Command les are a way of creating ones own commands. To dene a command le the rst line in the le 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 dened as a comment. This sign be placed any where in the le even before the MACRO-denition. To use the parameters in a command le one writes $ (parametername) . Command le must be in a le with name macroname.MCR. An example of an command le
MACRO komp reg start stop count echo off # default reg pidreg default start 1.0 default stop 5.0 default count 10 # define c define kk define step par 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

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 le 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 le 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 le 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

Chapter 5 The Syntax for Expressions


The following is the description of the syntex for RegSim in Bakus-Naur form. variable assignment ::= variable identier = expression parameter assignment ::= identier : constant | identier : vector constant [] | identier : 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 identier | identier ( expression , expression ) | ( expression ) | matrix constant

Regsim 3.8

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 identier ::= identier | identier{number , number} | identier[ identier ] | identier{number , number}[ identier ] identier ::= letter [ letter | underscore | digit | . ] matrix constant ::= {vector constant,vector constant} vector constant ::= {constant ,constant}

Regsim 3.8

Das könnte Ihnen auch gefallen