52
2 Description of the Wolfram SystemModeler
Below we discuss how to use if statements to represent conditional behavior. There
are two forms of conditional equations. The first is a balanced form, for example,
if a>b then
x = 5*time;
else
x = 3*time;
end if;
In the balanced case, the number of equations is always the same (one in the code
above), but each equation can change. This is important because for modeling in
Modelica the number of variables must be equal to the number of equations, and the
number of equations must be constant during the simulation.
Another type of conditional equations is equations in which the number of equations is not balanced. This means that the number of equations on the if side may not
be equal to the number of equations on the else side (as was the case in the balanced
case earlier), for example,
..
parameter Boolean steady_state;
initial equation
if steady_state then
der(x) = 0;
der(y) = 0;
end if;
..
In other words, if the logical parameter steady_state is true, then the original
equations will be satisfied. But if the parameter is false, it is not. The conditional
expression here explicitly has parametric variability, because the expression contains
only a variable, and this variable is a parameter. As a rule, the unbalanced form of
the if operator is used in the initial equations.
Basic information about the types of equations is contained in [4].
Consider the simplest differential equation:
dx
dt
= −x
With a given initial condition:
x 0 = 1
We write the equation with this initial condition in the Modelica language in the
text form Text View, as shown in Fig. 2.27.
2 Description of the Wolfram SystemModeler
Below we discuss how to use if statements to represent conditional behavior. There
are two forms of conditional equations. The first is a balanced form, for example,
if a>b then
x = 5*time;
else
x = 3*time;
end if;
In the balanced case, the number of equations is always the same (one in the code
above), but each equation can change. This is important because for modeling in
Modelica the number of variables must be equal to the number of equations, and the
number of equations must be constant during the simulation.
Another type of conditional equations is equations in which the number of equations is not balanced. This means that the number of equations on the if side may not
be equal to the number of equations on the else side (as was the case in the balanced
case earlier), for example,
..
parameter Boolean steady_state;
initial equation
if steady_state then
der(x) = 0;
der(y) = 0;
end if;
..
In other words, if the logical parameter steady_state is true, then the original
equations will be satisfied. But if the parameter is false, it is not. The conditional
expression here explicitly has parametric variability, because the expression contains
only a variable, and this variable is a parameter. As a rule, the unbalanced form of
the if operator is used in the initial equations.
Basic information about the types of equations is contained in [4].
Consider the simplest differential equation:
dx
dt
= −x
With a given initial condition:
x 0 = 1
We write the equation with this initial condition in the Modelica language in the
text form Text View, as shown in Fig. 2.27.
