0

the variable is now starting with j = 1, but the increment is wrong. For t = 0.5 it should have the value of 2 and for t = 1, j = 3 and so on... You see the error on the following image

variable j

class abc

import Modelica.SIunits;

parameter SIunits.Time delta_t = 0.5;

constant Real a[:] = {4,2,6,-1,3,5,7,4,-3,-6};

Real x;
Integer j(start=1);
Integer k = size(a,1);

algorithm
when {(sample(delta_t, delta_t) and j < k),j == 1} then

     x := a[pre(j)];
     j := pre(j) + 1;

end when;
end abc;

Thanks in advance.

lars
  • 23
  • 3

2 Answers2

0

When I put your code into Dymola 2013, I get exactly what you expected, j==2 @ time==0.5.

Where does this plot come from? Dymola does not generate plots like that since j is a discrete variables.

Michael Tiller
  • 9,291
  • 3
  • 26
  • 41
0

Ok, I found the problem. Dymola can generate plots like this, it depends on the output settings. The plot above was generated without the setting "Store variables at events", when I set this, I get the right result.

lars
  • 23
  • 3