function N=sequence(A,N0,T,maxN) % function N=sequence(A,N0,T,maxN) % % A is a parameter vector to be passed on to seqfnc. % % This function calculates the sequence up to element T % for the difference equation N_(t+1)=seqfnc(N_t) with N_0=N0. % % maxN is the largest value of N for the plots. % define the parameters R = A(1); K = A(2); % set up the vector of times t=[0:T]; % compute the sequence values by iteration % "N=0" is used to erase any values previously stored as "N". N = 0; N(1)=N0; for i=1:T N(i+1)=seqfnc(N(i)); end % plot the points (t,N) as "x". Set the axis ranges and labels. plot(t,N,'x') xlim([0,T]) ylim([0,maxN]) xlabel('\it{t}','FontSize',12) ylabel('\it{N}','FontSize',12,'Rotation',0) % the code that follows is used to compute the new population levels % the parameters need to have been defined earlier function y=seqfnc(N) y = N+R*N*(1-N/K); end end