Modelica. The difference between the section of the equation and the algorithm

Section of the equation: declarative

Algorithm Section: Non-declarative

Can someone help me with examples that show the difference between the two sections. When to use which section?

-Thanks

+4
source share
1 answer

The main difference between section algorithmand section equationis that each equation in a section is equationused to model the model. In the section algorithm, you have assignment operators that are required. This means that you can overwrite the influence of a previous assignment. As a concrete example, in the following section equation:

equation
  a = b;
  a = c;

. . , , algorithm

algorithm
  a := b;
  a := c;

.

" ", . algorithm . . , , . :

algorithm
  sum := 0;
  prod := 1;
  for i in 1:10 loop
    sum := sum + x[i];
    prod := prod * x[i];
  end for;

sum prod . , , , :

algorithm
  sum := 1+2+3+4+5+6+7+8+9+10;
  prod := 1*2*3*4*5*6*7*8*9*10;

... ...

equation
  sum = 1+2+3+4+5+6+7+8+9+10;
  prod = 1*2*3*4*5*6*7*8*9*10;

equation. equation:

equation
  sum = 0;
  for i in 1:10 loop
    sum = sum + i;

, 11 :

equation
  sum = 0;
  sum = sum + 1;
  sum = sum + 2;
  ...
  sum = sum + 10;

, 11 ! , .

, , algorithm , , , . , , - "" . equation .

P.S. - Modelica , , , , . , . Modelica, , . Modelica equation algorithm, . .

+10

All Articles