Environmental Engineering Reference
In-Depth Information
T = 100; % maximum time
r = [.5; .5]; % single species rates
a = [1; 1]; % alpha parameter
c0 = [0.1; 0.1]; % initial population density
%---------------------- execution ---------------------------------
options = odeset('AbsTol',1e-20);
[t,c] = ode15s(@PP,[0 T],c0,options,r,a);
%---------------------- graphical output -------------------------
subplot (2,1,1);
plot (c(:,1)',c(:,2)'); hold on;
legend ('trajectory');
xlabel ('predator'); ylabel ('prey');
subplot (2,1,2);
plot (t,c(:,1)','-',t,c(:,2)','--');
legend ('predator','prey');
xlabel ('time');
%---------------------- function ----------------------------------
function dydt = PP(t,y,r,a)
dydt = zeros(2,1);
dydt(1) = y(1)*(r(1)-y(2)*a(1));
dydt(2) = y(2)*(-r(2)+y(1)*a(2));
The complete code is included in the accompanying software under the name
“predprey.m”
In the output section the subplot command is used to place two plots with
different coordinate systems in the same figure. subplot can be used to place sub-
plots in one or more rows or columns (like a matrix) within the same MATLAB
®
figure. The command has three integer parameters. The first integer specifies the
number of rows, the second the number of columns, the third gives the 'serial
number' if sub-plots are counted along the rows first, starting with the uppermost
row. See the MATLAB
help for some instructive examples. Here two plots are
drawn, one above the other; the upper containing the phase space plot, the other a
visualization of the population time series. The output of the M-file with the data set
printed above is shown in Fig. 19.5 .
Both sub-plots show the characteristic oscillations of predator and prey
populations. When prey populations increase, the predator finds favourable
conditions, which leads to an increase of the predator population, too. With
increasing predatory stress the situation changes gradually for the prey, leading to
a decline of prey population, which finally results in unfavourable conditions for the
predator and a corresponding decline of the population. When the situation
becomes favourable for the prey, the entire loop starts again. The oscillations can
be observed in the second subplot, where the oscillating behavior of the prey
population is followed closely by the predator population curve.
The corresponding figure in the phase space is a closed curve, as depicted in the
upper subplot. The populations follow that curve in anti-clockwise direction. Along
®
Search WWH ::




Custom Search