Can anyone point me to suitable techniques for working with timescales other than seconds?
An example is the Lotka-Volterra 'classic model' on the following site: https://mbe.modelica.university/behavior/equations/population/
The resulting graph is shown with an x-axis from 1-120 seconds, but obviously that is not realistic for the rabbit/fox example. I've adjusted it in the following code snippet to give an idea of what I am looking for (with the assumption that alpha, beta, gamma and delta are actually rates/day).
My adjustments are a bit clunky and I'm sure there must be a nicer way, I just can't work it out.
I do want something compatible with the standard library and am using OpenModelica. Thanks!
model ClassicModel "This is the typical equation-oriented model"
parameter Real alpha=0.1 "Reproduction rate of prey per day";
parameter Real beta=0.02 "Mortality rate of prey per predator per day";
parameter Real gamma=0.4 "Mortality rate of predator per day";
parameter Real delta=0.02 "Reproduction rate of predator per day";
parameter Real x0=10 "Start value of prey population";
parameter Real y0=10 "Start value of predator population";
Real x "Prey population";
Real y "Predator population";
Real alpha_S=alpha/(60*60*24) "Reproduction rate of prey per second";
Real beta_S=beta/(60*60*24) "Mortality rate of prey per predator per second";
Real gamma_S=gamma/(60*60*24) "Mortality rate of predator per second";
Real delta_S=delta/(60*60*24) "Reproduction rate of predator per second";
initial equation
x=x0;
y=y0;
equation
der(x) = x*(alpha_S-beta_S*y);
der(y) = y*(delta_S*x-gamma_S);
end ClassicModel;
I think what you did is correct, and the issue is in the example. As you say, the rates are probably per day, but as it's just a demonstration it's easier to learn from it if the time numbers are not huge.
An improvements I would make is to omit the second set of parameters, and define the original ones as parameter Real alpha=0.1/(60*60*24)
etc.; this way the structure of the code stays simpler, it's clear and directly known what the actual rate comes out to (in case you compare to analytical results or similar), but you can still clearly adjust in the source code.
Another thing is that you can add parameter
in front of your _S
quantities, as they will not change during execution.