Lesson 11 of 15

Lotka-Volterra (Predator-Prey)

Lotka-Volterra Equations

The predator-prey model describes two interacting populations: prey xx (rabbits) and predators yy (foxes):

dxdt=αxβxyquad(prey grow, but die when meeting predators)\frac{dx}{dt} = \alpha x - \beta x y quad \text{(prey grow, but die when meeting predators)} dydt=δxyγyquad(predators grow by eating prey, die naturally)\frac{dy}{dt} = \delta x y - \gamma y quad \text{(predators grow by eating prey, die naturally)}

  • α\alpha: prey birth rate
  • β\beta: predation rate (prey killed per encounter)
  • δ\delta: predator growth rate per prey eaten
  • γ\gamma: predator death rate

Oscillations

The populations oscillate: when prey are abundant, predators multiply. More predators reduce prey. Fewer prey starve predators. Then prey recover, and the cycle repeats.

Equilibrium

There is a non-trivial equilibrium where both populations are constant:

x=γδ,y=αβx^* = \frac{\gamma}{\delta}, \quad y^* = \frac{\alpha}{\beta}

Starting exactly at this point, populations stay fixed forever.

Conservation Law

The Lotka-Volterra system has a conserved quantity (a "first integral"):

V=δxγlnx+βyαlny=constantV = \delta x - \gamma \ln x + \beta y - \alpha \ln y = \text{constant}

This means the phase-plane trajectories are closed curves.

Your Task

Implement lotka_volterra(alpha, beta, delta, gamma, x0, y0, t_end, n) using Euler's method. Return (x, y).

Pyodide loading...
Loading...
Click "Run" to execute your code.