% predprey.m - updated predator prey model for CDS 101/110
% RMM, Oct 07
%
% This file contains a simple model for a predator prey system. The
% model is developed following the treatment in the book by Murray
% (the other one).
%
% The states for these equations are
%
% x(1) # of rabbits (prey)
% x(2) # of foxes (predator)
%
% The equations allow for a quadratic term in both the predator and
% prey species that cause the population to fall off if you get too
% many of a given species. These terms are turned off by default.
%
function dxdt=predprey(t, x, flags, r, d, b, k, a, c)
% Extract the states
x1 = x(1);
x2 = x(2);
% Set up the parameter values [these should be passed as arguments...]
if (nargin < 4) r = 2; end;
if (nargin < 5) d = 0.7; end;
if (nargin < 6) b = 0.3; end;
if (nargin < 7) k = 10; end;
if (nargin < 8) a = 8; end;
if (nargin < 9) c = 4; end;
% Check to see if a feedback law has been defined
if (r < 0)
% Assume that the user has defined a function that we can call
% Add this value to the nominal value of the parameter (renegated)
r = predprey_rh(t, x, -r) - r;
end
dx1 = r * x1 * (1 - x1/k) - a * x2 * x1/(c + x1);
dx2 = b *a *x2 * x1 / (c + x1) - d * x2;
dxdt = [dx1; dx2];