% This matlab file simulates the Ricker difference equation for population dynamics
% The equation is given by x(n+1)=x(n)*exp(r*(1-x(n)/K)) where x(n) is the
% population abundance in the n-th generation, r is the intrinsic rate of
% growth, and K is the carrying capacity.
r=2.9; % defines r
b=3;
N=500; % N is the number of generations that you run the model.
x=zeros(N,1); % x stores the output of the model in a column vector with N elements
x(1)=0.1; %this determines the initial population density
for n=1:N-1 % this starts a do loop that iterates the model for next N-1 generations
x(n+1)=r*x(n)./(1+x(n).^b); %defines density in the next generation
end % ends the do loop
plot([1:1:N],x,'-o') %plots the data
xlabel('time'); %puts label on x axis
ylabel('abundance'); %puts label on y axis