
%==========================================================================
%REU Tutorial:  (Example Three)
%
%files_exampleII.m
%
%Use of mfiles and functions.  Initialization of large loop variables.
%
%Dependencies: 'logisticMap' and 'logisticOrbit'
%==========================================================================

clear
format long

    %how many parameter values?
    numPar=1500;

    %final time
    tf=1000;
    
    %Time axis
    t=linspace(0, tf, tf+1);

    %parameters
    r=linspace(1.9, 2.9, numPar);
    
    %an initial condition
    x_initial=0.2;
    
    %Initialize container
    X = zeros(numPar, tf+1);   %This is important.  Notice how slow
                               %the code runs if X is not initialized.
                               %While initialization is not necessary
                               %in MatLab, it will make large loops
                               %execute much faster (avoids a big 
                               %copy each time the loop executes).
    
    for i=1:numPar
        X(i,1:(tf+1)) = logisticsOrbit(x_initial, tf, r(i));
    end %end of numPar loop    
        
    %plot
    figure
    hold on
    for j=1:numPar
        thisParameter=r(j)*ones(1,tf+1-400);
        plot(thisParameter(:),X(j,400:tf),'.')
    end %end of plot loop    
    xlabel('parameter value','FontSize',8)
    ylabel('steady state','FontSize',8)
    title('Bifurcations of the logistics map','FontSize',10)
    
    
    
    
    
    
    
