predator_prey_ode, a C code which solves a pair of ordinary differential equations (ODE) that model a pair of predator and prey populations.
The physical system under consideration is a pair of animal populations.
The PREY reproduce rapidly; for each animal alive at the beginning of the year, two more will be born by the end of the year. The prey do not have a natural death rate; instead, they only die by being eaten by the predator. Every prey animal has 1 chance in 1000 of being eaten in a given year by a given predator.
The PREDATORS only die of starvation, but this happens very quickly. If unfed, a predator will tend to starve in about 1/10 of a year. On the other hand, the predator reproduction rate is dependent on eating prey, and the chances of this depend on the number of available prey.
The resulting differential equations can be written:
PREY(0) = 5000 PRED(0) = 100 d PREY / dT = 2 * PREY(T) - 0.001 * PREY(T) * PRED(T) d PRED / dT = - 10 * PRED(T) + 0.002 * PREY(T) * PRED(T)Here, the initial values (5000,100) are a somewhat arbitrary starting point.
The pair of ordinary differential equations that result have an interesting behavior. For certain choices of the interaction coefficients (such as those given here), the populations of predator and prey will tend to a periodic oscillation. The two populations will be out of phase; the number of prey will rise, then after a delay, the predators will rise as the prey begins to fall, causing the predator population to crash again.
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
predator_prey_ode is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version and an Octave version and a Python version.
euler, a C code which solves one or more ordinary differential equations (ODE) using the forward Euler method.
lorenz_ode, a C code which approximates solutions to the Lorenz system, creating output files that can be displayed by gnuplot.
midpoint, a C code which solves one or more ordinary differential equations (ODE) using the midpoint method.
spring_ode, a C code which shows how line printer graphics can be used to make a crude illustration of a solution of the ordinary differential equation (ODE) that describes the motion of a weight attached to a spring.
stiff_ode, a C code which considers an ordinary differential equation (ODE) which is an example of a stiff ODE.