- #1
Robben
- 166
- 2
Homework Statement
*I am not sure if this should be in the computer science section or here?
I am trying to graph the densities, of the Lotka-Volterra prey and predator model, as a function of time, i.e. ##p(t)## vs ##t## and ##q(t)## vs ##t##. Also, the phase space, i.e. ##p## vs ##q##, but I am not sure how to do that?
Let ##p## be the prey density and ##q## is the predator density, thus: $$\frac{dp}{dt} = ap\left(1-\frac{p}{K}\right)-\frac{bpq}{1+bp}$$ $$\frac{dq}{dt}=mq\left(1-\frac{q}{kp}\right).$$
Where ##bpq## is the interaction rate between the species, ##\frac{bpq}{1+bp}## is the effective rate of eating prey, ##m## is the mortality rate of the predators, ##K## and ##k## are the carrying capacitance of each population. Let ##a=0.2, \ m=0.1, \ K=500,\ k = 0.2.##
Homework Equations
$$p_i = p_{i-1}+\text{p-slope}_{i-1}\Delta t$$
$$q_i = q_{i-1}+\text{q-slope}_{i-1}\Delta t.$$
The Attempt at a Solution
We are also given ##a=0.2, \ m=0.1, \ K=500,\ k = 0.2, b = 0.1, p(0) = 10, q(0) = 5.## I chose ##\Delta t = h = 0.1.##
Thus:
$$\begin{align} p_i& = p_{i-1} + \left(0.2~ p_{i-1}\left(1 - \dfrac{p_{i-1}}{500}\right) -\dfrac{0.1~ p_{i-1}~ q_{i-1}}{1 + 0.1~ p_{i-1}} \right)(0.1) \\ q_i& = q_{i-1} + \left(0.1~q_{i-1}\left(1 - \dfrac{q_{i-1}}{0.2~ p_{i-1}}\right) \right)(0.1) \end{align}$$
Which gives the iteration:
##p_0 = 10, \ q_0 = 5##
##p_1 = 9.946, \ q_1 = 4.925##
##p_2 = 9.89538, \ q_2 = 4.85231##
##p_3 = 9.84803, \ q_3 = 4.78187##
##\ldots##
My java code:
Java:
public class Lotka {
public static void main(String[] args) {
double[] p = new double[1000];
double[] q = new double[1000];
p[0] = 10;
q[0] = 5;
for(int i = 1; i < 1000; i++) {
p[i] = p[i-1] + (0.2*p[i-1]*(1-p[i-1]/500)-(0.2*p[i-1]*q[i-1])/(1+0.2*p[i-1]))*0.001;
q[i] = q[i-1] + (0.1*q[i-1]*(1-q[i-1]/(0.2*p[i-1])))*0.001;
System.out.println("" + p[i] + " " + q[i]);
}
}
}