我对活动以及在Modelica中的时间感到困惑.下面是我的代码:
Hi I have some puzzles about event and when in Modelica. Below is my code:
model test Integer bar(start=5, fixed=true); equation when (time < 2) then bar = 1; end when; annotation(experiment(StopTime=3)); end test;我的问题是为什么当时间少于2时我得到5而不是1?在这种情况下,我如何理解事件(时间<2)? Modelica和其他编程语言(例如c)中的when子句有什么区别.
My question is why I got 5 instead of 1 when time is less than 2? How can I understand the event(time < 2) in this case? What is the difference of when clause in Modelica and other programming language, like c.
推荐答案Tobias的答案是正确的.但是我认为对于初学者来说,调用pre构造或将其发送到规范可能有些艰巨.因此,除了Tobias的答案外,我还会将感兴趣的读者指向此问题以及本章. (我怀疑)特别感兴趣的是when上的本小节以及如何它不同于if.
Tobias' answer is correct. But I think for beginners it might be a little daunting to invoke the pre construct or send them to the specification. So in addition to Tobias' answer, I would point the interested reader to this question as well as this chapter in my book. Of specific interest (I suspect) would be this subsection on when and how it is different from if.
更多推荐
何时和如果在Modelica中
发布评论