82
2 Description of the Wolfram SystemModeler
exception is the use of if inside functions, where, again, there is no requirement that
the number of equations be the same for both branches.
In the equations, you can also use the line form of the if statement.
if cexpr then expr1 else expr2
However, it can be in one of the parts of the equation. For example:
model Model1
Real x;
Boolean cond(start=true);
equation
der(x) = if cond then 1 else -1;
end Model1;
For details on the if statement, see reference [4].
The when statement is necessary when it is necessary to perform instantaneous
(with respect to model continuous time) actions. For example, it is necessary to
make a jump in the value of a variable when a condition is met. There can be various
equations in the actions of the when operator.
The when operator has the following general form:
when expr then
// Actions
end when;
Often in the actions of the when statement, use the reinit function, which allows
you to instantly change the value of a variable. The reinit function looks like this:
reinit(var, expr);
Here, var is a variable state whose value is to be changed and expr is an expression
whose calculation will give a new value for the variable var. As an expression, there
may be just a number.
It is worth mentioning the difference between if and when statements. Actions in
the when statement become active only for a moment when the discrete switching
condition becomes true. In other cases, the when statement has no effect on the
Précédent

- 95/274

Suivant