See textbook, Chapter 28.2
We often study systems in which there are several variables, which interact in complicated ways. One common situation involves a set of linked differential equations, in which the change in each quantity depends both upon it, and some other quantity.
One example of such a system is a predator-prey system. Ecologists who study very simple populations of animals sometimes find a cyclic pattern in the number of creatures. One good example is the population of snowshoe hares in Canada. There appears to be a cycle with a period of five or so years, between "busts" and "booms". The population of the hare's primary predator, the lynx, shows a similar cycle; but the two cycles are slightly out of phase.
One explanation for this pattern is that the hare and lynx populations are linked very strongly to each other.
One can express this set of relationships with a mathematical model:
Let x = number of hares y = number of lynx Then dx/dt = change in hare population = a * x - b * x * y dy/dt = change in lynx population = -c * y + d * x * yHere, the rate coefficients have rough meanings
Given some initial population of hares and lynx, and given the rate coefficients, you can follow the changes in each population as a function of time. Given the proper rate coefficients, you should see a "boom/bust" pattern in both hare and lynx numbers.
Write a MATLAB routine to calculate the number of hares and number of lynx as a function of time. Take as input the rate coefficients, and produce as output a set of three vectors of numbers:
function [t, hares, lynx] = population(a, b, c, d)where
t is the time (it will be measured in years) hares is the number of hares lynx is the number of lynx
Use Euler's method, and a timestep of less than a year (try somewhere between 0.01 and 0.20 years). Run the simulation for a total of 30 years. Use starting populations of:
x = 2 hares y = 1 lynxand use the following rate coefficients:
a = 1.2 b = 0.6 c = 0.8 d = 0.3
Inside your main loop over time, you should have code that looks something like this:
while (time < endtime) t(i) = current time hares(i) = current number of hares lynx(i) = current number of lynx calculate change in hares calculate change in lynx calculate new hare population calculate new lynx population i = i + 1; time = time + timestep; end
The vectors t, hares, lynx created by your program can be plotted quickly and easily within MATLAB like so:
[t, hares, lynx] = population(a, b, c, d) plot(t, hares); hold on; plot(t, lynx);
Last modified by MWR 4/24/2000.
Copyright © Michael Richmond. This work is licensed under a Creative Commons License.