% 
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(1:N-1),x(2:N),'r*')
hold on
xgr=0.:0.01:1. ;
ygr=r*xgr.*(1-xgr)
plot(xgr,ygr)
title('logistic map')
xlabel('x(n)')
ylabel('x(n+1)')
