54
2 Description of the Wolfram SystemModeler
The start attribute can also be used to help the resolver find the correct value for
a variable that is not a state variable. This can be explained in the example below.
The equation z
2
= 6 − z has two solutions, 2 and −3, respectively. To help the
solver find the desired solution, an initial (estimated) value can be given for z. This
value should be chosen as close as possible to the real solution. For example, if the
initial value 4 is used for z, the solution will be z = 2. If the initial value is -5, then
the solution will be z = −3. See Model2 and Model3 below.
model Model2
Real z(start=4);
equation
z^2=6-z;
end Model2;
Result: z=2
model Model3
Real z(start=-5);
equation
z^2=6-z;
end Model3;
Result: z=-3
The estimated values are useful when working with nonlinear equations, in particular, if the problem is to start the simulation from a relatively stable state. In this
case, the initial values for state variables can be used as estimated values.
It should be borne in mind that the initial value specified by the start attribute
is only recommended for the solver. If there are a large number of variables and
equations in the system, the solver selects initial values for the variables so that they
agree with each other; therefore, the actual initial values will not always coincide
with the values specified by the start attribute. If it is necessary to “hard” set initial
values, the attribute fixed=true is used (default is false) or other methods given
below. However, it is recommended to use the fixed attribute with caution, since a
large number of “hard” given initial values can contradict each other, which will
make it impossible to perform a computational experiment.
Another method of defining initial values for variables is to use sections of initial
equations or initial algorithms, which can be used, for example, to specify initial
values of derivatives (see Model4).
In Model4, x will always begin with a value of 1, while in Model1, the initial
value of the variable x can be easily changed by editing. If the value of a variable is
given by the initial equation, it is impossible to change its value by simply editing
the initial attribute. The initial equation section is more influential than the initial
attribute in all cases where the initial value can be calculated using the equation. For
example, in Model5, the value of the variable x will start from a static state, since
der(x)=0 is used as the initial equation.
Précédent

- 67/274

Suivant