function chaos( lambda0, lambda1, N ,M)
%CHAOS Display chaotic behaviour of g(x)=lambda x (1-x)
if (nargin<1)
    lambda0=0;
end
if (nargin<2)
    lambda1=4;
end
if (nargin<3)
    N=256;
end
if (nargin<4)
    M=256;
end
preiter=1024;
postiter=2048;
lambda=(0:N)/N*(lambda1-lambda0)+lambda0;
plot=sparse(N+1,M+1);
for i=1:N+1
    l=lambda(i);
    x=rand;
    %pre-iteration
    for j=1:preiter
        x=l*x*(1-x);
    end
    %post-iter
    for j=1:postiter
        x=l*x*(1-x);
        k=round(x*M);
        plot(N+1-i+1,k+1)=1;
    end    
end
spy(plot);
%format_ticks(gca,[],{num2str(lambda1),num2str(lambda0)},[],[1 M]);
title('Chaotic behaviour of \lambda x (1-x)');
%vorlsavepic('chaos');
end

