%% Logistic Equation Orbit

n=10000; %Number of sample points in r
m=4000; %Number of iterations of each orbit
rs=0;  %Starting value of r for creating bifurcation diagram
p=1000; %Number of final terms in orbit to sample

r=linspace(rs,4,n);
figure('units','normalized','outerposition',[0 0 1 1]);
hold on;

    for i=1:n,
                HorCoord=r(i)*ones(1,p);
            x(1)=rand;
        for k=1:m-1,
            x(k+1)=r(i)*x(k)*(1-x(k));
        end
        
        plot(HorCoord,x(m-p+1:m),'r.');
 %drawnow
        axis([rs,4,-.01,1]);
    end
hold off;
