TExcelTAD
Home › Differential Equations › Predator-Prey and Competition Models

Predator-Prey and Competition Models

Two interacting populations are the classic nonlinear system. Depending on the signs of the interaction terms they model predation (one species eats the other) or competition (both want the same food). The linearization tools of this chapter predict who survives.

The Lotka-Volterra predator-prey model

Prey xx (rabbits) grow on their own; predators yy (foxes) die without prey; encounters, proportional to xyxy, remove prey and feed predators:

x′=ax−bxy,y′=−cy+dxy.x' = ax - bxy, \qquad y' = -cy + dxy.

Critical points: (0,0)(0, 0) and (cd,ab)\left(\frac{c}{d}, \frac{a}{b}\right). The Jacobian at the origin has eigenvalues aa and −c-c: a saddle. At the coexistence point it has eigenvalues ±iac\pm i\sqrt{ac}: a linear center. Here the center survives, because the system has a conserved quantity

H(x,y)=dx−cln⁡x+by−aln⁡y,H(x, y) = dx - c\ln x + by - a\ln y,

whose level curves are closed. Populations cycle forever, the predator peak lagging behind the prey peak.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp

a, b, c, d = 1.0, 0.1, 1.5, 0.075
H = lambda x, y: d * x - c * np.log(x) + b * y - a * np.log(y)
sol = solve_ivp(lambda t, z: [a*z[0] - b*z[0]*z[1], -c*z[1] + d*z[0]*z[1]], (0, 30), [10.0, 5.0],
                dense_output=True, rtol=1e-10, atol=1e-12)
t = np.linspace(0, 30, 3001)
x, y = sol.sol(t)
print("equilibrium:", (c / d, a / b))
print(f"prey range [{x.min():.2f}, {x.max():.2f}], predator range [{y.min():.2f}, {y.max():.2f}]")
print(f"H drift over 30 time units: {np.ptp(H(x, y)):.1e}")
print(f"first prey peak at t = {t[np.argmax(x[:1000])]:.2f}, first predator peak at t = {t[np.argmax(y[:1000])]:.2f}")
equilibrium: (20.0, 10.0)
prey range [7.93, 40.60], predator range [3.09, 23.28]
H drift over 30 time units: 6.7e-10
first prey peak at t = 2.49, first predator peak at t = 3.39

The average populations over one cycle equal the equilibrium values, a surprising consequence of the model ("Volterra's principle"): fishing both species reduces the average prey less than you would think and the average predators more.

A more realistic variant

Lotka-Volterra cycles are structurally fragile: any small change to the model can turn the center into a spiral. Adding a carrying capacity for the prey,

x′=ax(1−xK)−bxy,x' = ax\left(1 - \frac{x}{K}\right) - bxy,

makes the coexistence point a spiral sink: oscillations damp out and the populations settle.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp
import sympy as sp

a, b, c, d, K = 1.0, 0.1, 1.5, 0.075, 100.0
X, Y = sp.symbols("x y")
F = sp.Matrix([a*X*(1 - X/K) - b*X*Y, -c*Y + d*X*Y])
eq = {X: c / d, Y: a / b * (1 - c / (d * K))}
print("coexistence point:", {k: round(float(v), 3) for k, v in eq.items()})
print("eigenvalues:", [complex(e) for e in F.jacobian([X, Y]).subs(eq).evalf().eigenvals()])
sol = solve_ivp(lambda t, z: [a*z[0]*(1 - z[0]/K) - b*z[0]*z[1], -c*z[1] + d*z[0]*z[1]], (0, 200), [10.0, 5.0], rtol=1e-9)
print("state at t = 200:", np.round(sol.y[:, -1], 3))
coexistence point: {x: 20.0, y: 8.0}
eigenvalues: [(-0.10000000000000003-1.0908712114635715j), (-0.10000000000000003+1.0908712114635715j)]
state at t = 200: [20.  8.]

Competition

For two species competing for the same resource,

x′=x(α1−β1x−γ1y),y′=y(α2−β2y−γ2x),x' = x(\alpha_1 - \beta_1x - \gamma_1y), \qquad y' = y(\alpha_2 - \beta_2y - \gamma_2x),

the outcome depends on whether competition between species is stronger than within each species. In the example of Critical Points and Linearization, the coexistence point was a saddle: one species always wins (competitive exclusion). If each species limits itself more than it limits the other, the coexistence point is a sink and both survive.

In software

  • Population ecologists fit these models to data with solve_ivp inside an optimizer (scipy.optimize.least_squares), the same workflow as the epidemic fitter at the end of this course.
  • Game designers use predator-prey dynamics to balance simulated ecosystems and in-game economies (resources versus consumers), and the cycles explain boom-and-bust behaviour players notice.

Exercises

Exercise 1: Equilibrium

Find the coexistence point of x′=2x−0.5xyx' = 2x - 0.5xy, y′=−y+0.25xyy' = -y + 0.25xy.

Answer

(4,4)(4, 4).

Solution

y′=0y' = 0 with y≠0y \ne 0 gives x=10.25=4x = \frac{1}{0.25} = 4; x′=0x' = 0 with x≠0x \ne 0 gives y=20.5=4y = \frac{2}{0.5} = 4.

Exercise 2: Cycle period near the center

What is the approximate period of small oscillations around the coexistence point in Exercise 1?

Answer

2π2≈4.44\frac{2\pi}{\sqrt{2}} \approx 4.44.

Solution

The eigenvalues are ±iac=±i2⋅1\pm i\sqrt{ac} = \pm i\sqrt{2 \cdot 1}, so small cycles have angular frequency 2\sqrt{2}.

Exercise 3: Averages over a cycle (code)

For the lesson's parameters, check numerically that the average prey and predator populations over one cycle equal cd=20\frac{c}{d} = 20 and ab=10\frac{a}{b} = 10.

Answer

The averages come out as 20 and 10 (to the accuracy of the integration).

Solution

Integrate exactly one cycle (detect the return to the starting prey value while prey is increasing) and average.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp
a, b, c, d = 1.0, 0.1, 1.5, 0.075
f = lambda t, z: [a*z[0] - b*z[0]*z[1], -c*z[1] + d*z[0]*z[1]]
back = lambda t, z: z[0] - 10.0
back.direction = 1
s = solve_ivp(f, (0, 30), [10.0, 5.0], events=back, rtol=1e-11, atol=1e-12)
T = s.t_events[0][1] if s.t_events[0][0] < 1e-6 else s.t_events[0][0]
s2 = solve_ivp(f, (0, T), [10.0, 5.0], dense_output=True, rtol=1e-11, atol=1e-12)
t = np.linspace(0, T, 200001)
x, y = s2.sol(t)
print(round(T, 4), round(np.trapezoid(x, t) / T, 4), round(np.trapezoid(y, t) / T, 4))
5.4797 20.0 10.0

Test yourself

In the Lotka-Volterra model, the coexistence equilibrium is…

  1. a sink
  2. a center surrounded by closed cycles
  3. a saddle
  4. a source

Adding a prey carrying capacity to Lotka-Volterra typically…

  1. makes the populations explode
  2. turns the cycles into damped oscillations toward equilibrium
  3. removes the equilibrium
  4. has no effect

In a predator-prey cycle, the predator peak…

  1. comes before the prey peak
  2. lags behind the prey peak
  3. coincides with it
  4. never happens