%3. Set Parameters
a=0.69; b=0.06; c=0.02; d=0.5; e=0.03;
%reduce parameters for small time steps
as=a/nsteps; bs=b/nsteps; cs=c/nsteps;
ds=d/nsteps; es=e/nsteps; ct = 0;
%4. Main daily loop
for i=1:ndays
%Variant 2: Remove next “%” to
% randomly vary a (0.52 to 0.86)
%as= a*(1.+ 0.5*(rand-0.5))/nsteps;
%5. “Euler” loop to closely track the
% solution:
for j=1:nsteps
ct = ct+1;
T(ct)=ct/nsteps;
P(ct)=PP; Z(ct)=ZZ;
dP=as*PP-bs*PP*ZZ;
dZ=cs*PP*ZZ-ds*ZZ;
% Variant 2: Remove next “%” to add
% grazer cannibalism
%dZ=dZ-es*ZZ*ZZ;
PP=PP+dP; ZZ=ZZ+dZ;
end
end
%Graph result
figure;
plot(T(1:end),P(1:end),′g′); hold on
plot(T(1:end),Z(1:end),′r′);
axis([0 60 0 100]);
(^) Same instructions as at bottom of Box 4.1.
Fig. 4.2 (a) Persistent oscillations of a Lotka–Volterra model of phytoplankton–grazer
interaction with no damping process, plotted as a time-series. (b) The same
phytoplankton–grazer relationship, but with the grazers slightly self-limiting (a
quadratic damper term added). (c) Exactly like (b), but with random variation of the
phytoplankton growth rate.