
% Bifurcation diagram for logistic map


g = inline('a*x.*(1-x)','a','x');

Npts=200;
Ntrans=100;
Ntot=Ntrans+Npts;
fig1=1;

% For the whole window:
amin = 2.9;
amax = 4;
xmin=0;
xmax=1;
Na = 200;

aa = linspace(amin,amax,Na);

x0=0.1;

ms=5;
lw=2;
fs=15;

figure(fig1);clf
p1 = plot(amin-1,x0,'.','EraseMode','none','MarkerSize',ms);
axis([amin amax xmin xmax]);
hold on
set(gca,'FontSize',[fs]);
xlabel('a'); ylabel('x_n');
title(['Logistic map: bifurcation diagram']);


XX=[];
X=[x0];
xo=x0;

for a=aa
 xo=xo+1e-10;
 A=ones(1,Npts)*a;
 for i=1:Ntot
  xn=g(a,xo);
  X=[X xn];
  xo=xn;
 end

 XX=[XX ; X(Ntrans+1:Ntot)];

 set(p1,'Xdata',A,'YData',X(Ntrans+1:Ntot))
 drawnow

 X=[X(Ntot:Ntot)];
end

figure(fig1)
plot(aa,XX,'.','MarkerSize',ms);

