% Logistic.m % Author: Adolfo J. Rumbos % This program allows the user to input initial condition for a logistic % differnce equation. It also allows for the input of the intrinsic growth % rate. The carrying capacity is assumed to be K=1. The program can also % iterate the equation for as many generations as desired. % % disp(' ') disp('This program finds and plots solutions to the logistic difference equation') disp(' ') disp(' N_{t+1} = N_t + r*N_t*(1-N_t)') disp(' ') disp(' ') disp('Enter the intrinsic growth rate "r"') r=input ('r = '); % disp(' ') disp('Enter the initial population value "N_0"') N_0=input ('N_0 = '); % disp(' ') disp('Enter the number of generations:'); gen=input('(Default is 20) '); if isempty(gen) gen=20; end; % p=N_0; N=p; for i=1:gen; p = p + r*p*(1 - p); N=[N p]; end % % Plotting routine plot([0:gen], N, 'k-*') y_max = max([N_0 N]) + 0.1; axis([0 gen 0 y_max]); grid on; title(['Logistic model with r = ', num2str(r), ', K=1, ', 'and ', 'N\_0 = ', num2str(N_0)]) xlabel('Time t'); ylabel('Population N');