Documentation

Initial Equations

Regular equations are executed throughout the simulation. The (Initial=true) attribute lets you specify additional equations that are executed during model initialization only.

Regular component equations alone are not sufficient to initialize a DAE system. Consider a system with n continuous differential variables and m continuous algebraic variables. For simulation, this system has n+m degrees of freedom and must provide n+m equations. The initialization problem has up to n additional unknowns that correspond to the derivative variables. These additional unknowns can be satisfied when you specify initial targets for block variables. Initial equations provide another way to initialize a system.

In general, the maximum number of high-priority targets you can specify is equal to the number of additional unknowns in the initialization problem. Besides the unknowns from differential variables, the initialization problem also has one more unknown for each event variable. These additional unknowns determine the maximum combined number of initial equations and high-priority variable targets. If there are too many high-priority targets, these cannot all be met. For more information, see Block-Level Variable Initialization.

Because the default value of the Initial attribute for equations is false, you can omit this attribute when declaring regular equations:

equations (Initial = true)  % initial equations
[...]
end

equations (Initial = false) % regular equations
[...]
end

equations % regular equations
[...]
end

The syntax of initial equations is the same as that of regular equations, except:

• der(x) in initial equations is treated as an unknown value and is solved for during initialization.

• delay and integ operators are disallowed.

When you include assert constructs in initial equations, their predicate conditions are checked only once, after solving for initial conditions (before the start of simulation, see Initial Conditions Computation). Use these assertions to safeguard against the model initializing with nonphysical values. For more information, see Programming Run-Time Errors and Warnings.

A common use case for specifying initial equations is to initialize a system in steady state, for example:

component C

parameters
a = {-5, '1/s'};
b = {-2, '1/s'};
end

outputs
x = 5;
y = 10;
end

equations
der(x) == a*x + b*y;
der(y) == b*y;
end

equations(Initial=true)
der(x) == 0;
der(y) == 0;
end

end

At initialization time, the equations are:

der(x) == 0;
der(y) == 0;
der(x) == a*x + b*y;
der(y) == b*y;

For the rest of the simulation, the equations are:

der(x) == a*x + b*y;
der(y) == b*y;