Main Content

initial

Specify initial mode in mode chart

Syntax

initial init_mode : predicate_condition end     

Description

initial begins the initial mode construct in a mode chart. The construct is terminated by an end keyword. It contains one statement with the following syntax:

init_mode : predicate_condition

where:

  • init_mode is the mode active at the start of simulation if the expression in the predicate_condition is true.

  • If predicate_condition is false, then the first mode listed in the modes section is active at the start of simulation.

The predicate_condition must be a parametric expression because it is evaluated at compile time. Using a variable in a predicate results in a compile-time error.

The initial construct is optional. If a mode chart does not contain an initial construct, then the first mode listed in the modes section is active at the start of simulation.

For example, a mode chart declares three modes, m1, m2, and m3:

modes
    mode m1
    ...
    end
    mode m2
    ...
    end
    mode m3
    ...
    end
end

By default, mode m1 is active at the start of simulation. If you include the following initial construct:

initial
    m2 : p1
end

then, if the p1 predicate is true, simulation starts in mode m2; otherwise, in mode m1.

The initial construct can have multiple initial mode statements, for example:

initial
    m2 : p1
    m3 : p2
end

In this case:

  • If the p1 predicate is true, simulation starts in mode m2.

  • If the p2 predicate is true, simulation starts in mode m3.

  • If both predicates are true, simulation starts in mode m2 (the first one listed in the initial section).

  • If both predicates are false, simulation starts in mode m1 (the first one listed in the modes section).

At initialization time, the solver sets the initial mode first, and then checks the transitions. If a transition predicate is true at initialization time, the system might start in a different mode than that specified by the initial construct. For example, consider a mode chart that declares three modes, m1, m2, and m3, and defines the following transitions and initial modes:

transitions
    m3 -> m2 : p1
end
initial
    m2 : p2
    m3 : p3
end

If predicates p1 and p3 are both true at initialization time, the solver sets m3 as the initial mode, but the system immediately transitions from mode m3 to mode m2, and simulation starts in mode m2.

Version History

Introduced in R2017a