% The purpose of this code is to simulate the Nicholson Bailey model (Beddington)  for 
% host-parasitoid interaction

clear;


%set the number of iterates
M = 10000;

%set the parameters (the last one set is the one currently being used.)
r = 2.1;  % this is the bifurcation point;  Below is stable above is unstable
r = 1.999
r = 2.02;
;
% the fixed point has x = y = 1-1/r;
%set the initial data
 

x0 = 1-1/r;
y0 = 1-1/r;
x = x0;
y = y0+.1;


%store the initial data
X(1) = x;
Y(1) = y;


%iterate
for j=2:M

%evaluate the functions %The beddington model:

X_new = r*x*(1-y);
Y_new = x;


%store the current values
X(j) = X_new;
Y(j) = Y_new;

%update
x = X_new;
y = Y_new;
end

%make some plots
figure(1)
plot([1:M],X,'b',[1:M],Y,'r',[1:M],X,'b*',[1:M],Y,'r*')

figure(2)
plot(X,Y,'*',x0,y0,'r*',X(1),Y(1),'g*')

