如何在 Modelica 中对预定时间发生的单个时间事件进行建模?

How do I model a single time event in Modelica occurring at a predetermined time?

我想对一个连续时间系统建模,该系统会在预先知道的特定时刻改变其行为。一个小例子如下

model time_event
  Real x(start = 0)  "state variable for this example";
  parameter T_ch = 5 "time at which the system dynamics undergoes a change";
equation
  if time <= T_ch then 
    der(x) = x + 1;
  end if;
  if time > T_ch then
    der(x) = -x;
  end if;

end time_event;

您的解决方案几乎没问题。以下是您的代码,经过一些修改。

  • 用过if then else也可以做if then elseif then elseif then ... else
  • 添加了平衡变量 xb 以具有共同的导数方程(不需要只是一种编码风格)。

代码:

model time_event      
    Real x(start = 0)  "state variable for this example";
    parameter Real T_ch = 5 "time at which the system dynamics undergoes a change";
    Real xb "Balance variable for derivative";
equation
    der(x) = xb; 
    if time <= T_ch then 
        xb = x + 1;
    else
        xb = -x;
    end if;
end time_event;

结果图:

红色 = x

蓝色 = der(x)