function logistic
% LOGISTIC iterates the logistic map
%   x_{n+1} = mu*x_n*(1-x_n)

% Copy file logistic.m to the MATLAB home directory
% Start MATLAB and enter "logistic" to run script

% Set parameters
    N = 100;                        % number of iterates to plot
    N0 = 100;                       % discard first N0 iterates
    mu0 = 1.;                       % minimum mu-value to plot
    mu1 = 4.;                       % maximum mu-value to plot    
    N1 = N + N0;                    % finish plotting at N1 iterates
    disp('Enter mu-values between 1 and 4. Enter 0 to stop.');
    mu = input('Enter mu: ');       % enter first value of parameter mu
    figure(1);                      % open figure
    hold on;                        % keep plots from previous mu-values
    axis([mu0 mu1 0 1]);            % set mu and x limits on axes
    xlabel('\mu');                  % label axes
    ylabel('x');                        
    while mu > 0
        m = mu*ones(1,N1);          % vector of mu-values (all equal to mu)
        x = zeros(1,N1);            % initialize x-vector
        x0 = 1/pi;                  % starting value for x-iterates
        x(1) = x0;                  % set initial value for iterations
% Iterate logistic map
        for n = 2:N1            
            x(n) = mu*x(n-1)*(1.0-x(n-1));
        end    
% Plot result
        xplot = x(N0+1:N1);         % select values with N0+1 \le n \le N1
        mplot = m(N0+1:N1);
        plot(mplot,xplot,'.');      % plot selected iterates
        mu = input('Enter mu: ');   % enter next value of parameter mu
    end
end
