%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% logbif 
%%
%% Make a bifurcation diagram for the discrete logistic map
%%
%%  x_{n+1} = lambda * x_n * (1-x_n)
%%
%%    logbif( x0, N, n)
%%
%%      x0:   initial iteration value
%%       N:   Number of iterations to compute
%%       n:   use the last 'n' iterates for the plot
%%
%%

function logbif(x0,N,n)
  nlam = 500;
  lam = linspace(0,3.95,nlam);
  one = ones(1,N);
  
  if ~exist('n')
    n=N-1;
  end
  
  X=[];
  Y=[];
  for k=1:nlam
    x=dlog(lam(k),x0,N);
    x=x(N-n:N);
    y=lam(k)*ones(1,length(x));
    X=[X,x];
    Y=[Y,y];
  end
  plot(Y,X,'.')
end
