Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Matlab code for Lotka-Volterra predator prey model.


%
% Pred_runge.m
%
% This program implements a numerical integration of the
% Lotka-Volterra predator-prey model using Second order Runge-Kutta.
% The form of this code is more matlab style than pred.m
%
% Author: L.G. de Pillis
% Date: January 1997
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=1.0;
b=0.5;
c=0.75;
d=0.25;

% (a-bW) is the intrinsic growth rate of the krill


%
% (-c+dK) is the intrinsic growth rate of the whales
%

% Set initial conditions


tinit = 0.0;
% start time
tfinal = 50.0; % stop time
K1(1)=5.0;
% intial krill population
W1(1)=1.0;
% intial whale population
n = 2000;
% number of time steps
dt = (tfinal-tinit)/n; % time step size
T=[tinit:dt:tfinal]; % create vector of discrete solution times
% Execute second order RK
for i = 1:n
k1 =
K1(i) + 0.5*dt*K1(i)*(a-b*W1(i));
w1 =
W1(i) + 0.5*dt*W1(i)*(-c+d*K1(i));
K1(i+1) = K1(i) + dt*k1*(a-b*w1);
W1(i+1) = W1(i) + dt*w1*(-c+d*k1);
end;
%Plot Results...
S1 = sprintf('IC: W0=%g, K0=%g',W1(1),K1(1));
figure(1)
clg;
plot(K1,W1);
title('Phase Plane Plot');
xlabel('Krill');
ylabel('Whales');
legend(S1,0);
grid;
figure(2)
clg;
plot(T,K1,'r-',T,W1,'g-.');
legend('Krill','Whales');
xlabel('time');
ylabel('whales and krill');
title(S1)

You might also like