%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% solves the Predator-prey equations            %
%                                               %
%   x' = rx - axy                               %
%   y' = bxy - ky                               %
%                                               % 
% requires the use of file:  predprey.m         % 
% eqs. from p. 166 of K K Tung's book           % 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear;

global r;
global a;
global b;
global k;


  r = .035;%.1;
  a = .001;%.1;
  b = .0001;%.1;
  k = .03;%.5;

% time span of integration
  tspan = [0 1000];
% initial conditions
x0 = 250;%180;%200;%10;
y0 = 40;%60;%50;%2;
v0 = [x0,y0];

% solves ode using ode45 routine

[t,vout] = ode45(@predprey,tspan,v0);

% 
%   plots y(t) for xstar=0.0 in an upper subplot
%

% note:
%%paramstring = sprintf( ', {\\itb}=%d, {\\itc}=%d,{\\itx_0}=%d', b, c, xstar);

figure(1)
clf
subplot(2,1,1)

plot( t, vout(:,1),'.' );
xlabel( '{\itt}' );
ylabel( '{\itx}({\itt})' );
title('Prey')
axis tight;
grid on;

subplot(2,1,2)

plot( t, vout(:,2),'.' );
xlabel( '{\itt}' );
ylabel( '{\ity}({\itt})' );
title( 'Predator')
axis tight;
grid on;