我是 OpenModelica 的新手,我对与软件一起作为示例代码分发的“BouncingBall.mo”的代码有几个问题。
1) 'when'和'if'和有什么不一样?
2)代码中变量'foo'的目的是什么?
3)在第(15)行 - “当 {h <= 0.0 and v <= 0.0,impact}”时, 'when'的表达式不应该足够“{h <= 0.0 and v <= 0.0} ”因为当影响发生时这变为真,影响的目的是什么(对我来说这里是多余的)以及影响之前的逗号(, )是什么意思?
model BouncingBall
parameter Real e = 0.7 "coefficient of restitution";
parameter Real g = 9.81 "gravity acceleration";
Real h(start = 1) "height of ball";
Real v "velocity of ball";
Boolean flying(start = true) "true, if ball is flying";
Boolean impact;
Real v_new;
Integer foo;
equation
impact = h <= 0.0;
foo = if impact then 1 else 2;
der(v) = if flying then -g else 0;
der(h) = v;
when {h <= 0.0 and v <= 0.0,impact} then
v_new = if edge(impact) then -e * pre(v) else 0;
flying = v_new > 0;
reinit(v, v_new);
end when;
end BouncingBall;