% Filename: LogisticDifferenceEqn
% M-file to simulate the logistic difference equation
% Set the values of r and x0
r = 3.0;
x0 = 0.2;
% Through the loop we will fill the values x_n into the array x
% In the first iteration of the loop, the value of x(1) needs to be known
% We set that value before starting
x(1) = x0;
for t = 1:50
x(t+1) = x(t) + r*x(t)*(1-x(t));
end
% Plot results
plot(x,'r.-','MarkerSize',12)
xlabel('Time Step')
ylabel('Population Density')