You job in this lab is to write a Java application to simulate the population of lynxes and hares using the Lotka-Volterra equations presented in class.
dH = a*H - alpha*HPThese equations have 2 variables (H, and P) and 4 constants (a, b, alpha, and, beta). H is the number of herbavores, P, the number of predators, a is the birth rate for herbavores, b the death rate for predators, alpha is the proportion of Hs eaten by Ps, and beta is the proportion of eaten herbavores that are converted to new predators. dH means the change in H (in one time step), dP, the change in P.
dP = beta*H*P - b*P
These were originally differential equations, but in this program we will treat them as difference equations.
Empirical findings show that the populations of hares and lynx (in the Hudson Bay region, in the late 1800's) tend to oscillate, with the predator changes following the prey. I.e. after a rise in H, there is a rise in P, then a fall in H followed by a fall in P; then a rise in H, and the cycle continues. Your task is to implement a simulation of these equations, and then, discover values for the initial populations of hares and lynxes, plus the four constants, that produce behavior in the model that is something like the real system. I.e. with oscillations of both populations.
P=0. That only leaves one equation:
int H=1000;
double a = 0.01;
These declarations should be inside the class {}s, but outside any method {}s (so they will be visible everywhere in the class).
takeStep() method, that might look like this:
void takeStep() {
double dH = a * H;
H += dH;
output();
}
And output() looks like:
void output() {
System.out.println("H="+ H);
}
Then, you only need to add one line in the actionPerformed() method for the Button (remember, Netbeans writes the shell of the method for you):
private void stepButtonActionPerformed(java.awt.event.ActionEvent evt) {
takeStep();
}
Run your program for a few hundred steps and see how those bunnies multiply!
something(); happen 100
times you can write:
for (int i=0; i<100; i++) {
something();
}
That's all it takes.
Try to find initial values for H and P and for the four constants, that yield at least a few oscillations. To do this, add two TextFields, one to enter the initial herbavore population, another to enter the initial predator population (then you won't have to recompile every time you want to try new starting H and P values).