何时和如果在Modelica中 [英] When and If in Modelica

查看:82
本文介绍了何时和如果在Modelica中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对活动以及在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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆