Tags and keywords
model QuiescentModelUsingStart "Find steady state solutions to LotkaVolterra equations"
parameter Real alpha=0.1 "Reproduction rate of prey";
parameter Real beta=0.02 "Mortality rate of predator per prey";
parameter Real gamma=0.4 "Mortality rate of predator";
parameter Real delta=0.02 "Reproduction rate of predator per prey";
Real x(start=10) "Prey population";
Real y(start=10) "Predator population";
initial equation
der(x) = 0;
der(y) = 0;
equation
der(x) = x*(alpha-beta*y);
der(y) = y*(delta*x-gamma);
end QuiescentModelUsingStart;
Because of various limitation of SysPhS-1.1 some workarounds were required to get this one to work.
The exported Modelica code is:
model QuiescentModelUsingStart
parameter Real alpha(start=0.1,fixed=true);
parameter Real beta(start=0.02,fixed=true);
parameter Real gamma(start=0.4,fixed=true);
parameter Real delta(start=0.02,fixed=true);
Real x(start=20.0,fixed=true);
Real y(start=5.0,fixed=true);
Real dx(start=0.0,fixed=true);
Real dy(start=0.0,fixed=true);
equation
der(x)=x*(alpha-beta*y);
der(y)=y*(delta*x-gamma);
dx=der(x);
dy=der(y);
end QuiescentModelUsingStart;
Because of the lack of explicit support for 'initial equation', additional variables dx
and dy
with equations dx = der(x)
and dy = der(y)
with start values 0 were introduced in the SysPhS version. But they are not in fact compatible with the non-fixed 'start' values in the Modelica University version:
Real x(start=10) "Prey population";
Real y(start=10) "Predator population";
initial equation
der(x) = 0;
der(y) = 0;
equation
der(x) = x*(alpha-beta*y);
der(y) = y*(delta*x-gamma);
That doesn't matter for the Modelica University version, but it does matter if you try to mimic it with SysPhS, because currently (in SysPhS-1.1) default values are always assumed to be 'fixed', not mere "suggestions" for iteration variables:
Wolfram SystemModeler correctly complains if you use x(start=10,fixed=true)
and y(start=10,fixed=true)
.
To get around this, in the SysPhS version a HACK was used, the "correct" steady values x=20
and y=5
were chosen as forced default values. Then it validates in Wolfram SystemModeler and runs (and you can see it indeed flat-lines at those values).