% tutorial for matlab, for the course in nonlinear dynamics and
% chaos
%  Einat and Eli
clear all; close all;
% solve and plot logistic map:
% x(n+1)=r*x(n)*(1-x(n))

% number of steps:
N=100;

% initial conditions:
x(1)=0.2;

% parameter:
% r=3.8;  % chaos
% r=2.0;  % steady state
 r=3.2;   % period 2
% r=3.5;   % period 4?

for n=1:N
  x(n+1)=r*x(n)*(1-x(n));
end

plot(x)
title('logistic map')
xlabel('n')
ylabel('x(n)')

figure
plot(x(2:N),x(1:N-1),'*')
title('logistic map')
xlabel('x(n+1)')
ylabel('x(n)')
