function Yp = perrhs ( tau, Y );
% PerRHS
%
% This m-file is part of the material of the lecture
%   Scientific Computing and Software Tools
% at the Math Department of Halle University, Germany.
% Summer term 2004
%
% Author :      Prof. Dr. M. Arnold, arnold@mathematik.uni-halle.de
% Version of :  May 25, 2004
%
% Right hand side for predator-prey problem with periodic solution
%
% Reference:
%   J.D. Murray: Mathematical Biology I, 3rd ed. - Springer - 2002.
%     Section 3.4
%
% Parameters:
%   tau    (input)  : normalized time t / T with T=Y(ny+1), ny=2
%                     Set T=Y(ny+1)=1.0 for evaluation in real time scale.
%   Y      (input)  : actual state
%   Yp     (output) : actual value of the right hand side
%
% Example:
%   [ t, y ]  = ode45 ( @perrhs, [ 0 1 ], [ 0.3 0.1 1000 ]' );
%   plot ( y(:,1), y(:,2) );

% -> parameter
a = 2.0;
b = 0.1;
d = 0.2;

% -> read input data
nY = length ( Y );
ny = nY - 1;

u = Y(1);
v = Y(2);

T = Y(ny+1);

% -> right hand side
up = u * ( 1 - u ) - a * u * v / ( u + d );  % Murray, (3.20) 
vp = b * v * ( 1 - v / u );                  % ! misprint has been corrected

yp = [ up; vp ];   % right hand side of predator-prey problem in real time scale
Yp = [ T*yp; 0 ];  % rescaling to normalized time \tau