在我的模型中,我对为什么没有完全指定初始条件感到困惑。
下面是代码和截图:
model WithAlgebraicLoop_Right
extends Modelica.Icons.Example;
Real x;
Real y(start=1, fixed=true);
Boolean cond;
equation
cond = x > 0.5;
when pre(cond) then
y = 1*time;
end when;
x = sin(y*10*time);
end WithAlgebraicLoop_Right;
Run Code Online (Sandbox Code Playgroud)
我认为在初始化期间,x可以从 计算y,所以cond可以从 计算x,那么为什么 Dymola 没有像我想的那样做呢?
当然,离散时间变量cond可以根据给定的方程进行计算。但是,它在初始化时事件迭代的预值是未知的,必须通过设置固定的起始值或初始方程来设置,无论您喜欢什么。
model WithAlgebraicLoop_Right1
Real x;
Real y(start=1, fixed=true);
Boolean cond(start=false, fixed=true);
equation
cond = x > 0.5;
when pre(cond) then
y = 1*time;
end when;
x = sin(y*10*time);
end WithAlgebraicLoop_Right1;
Run Code Online (Sandbox Code Playgroud)
或者
model WithAlgebraicLoop_Right2
Real x;
Real y(start=1, fixed=true);
Boolean cond;
initial equation
pre(cond) = false;
equation
cond = x > 0.5;
when pre(cond) then
y = 1*time;
end when;
x = sin(y*10*time);
end WithAlgebraicLoop_Right2;
Run Code Online (Sandbox Code Playgroud)