function time_series(Niter,x0);
% TIME_SERIES: Create a time series plot for a dynamical mapping function.

% TIME_SERIES(Niter,x0) creates a time series plot (x_n vs. n) for a 
% mapping function (usually defined in the MAPPING subfunction below).  
% The initial condition for the system is set by 'x0'.  The mapping is 
% performed a total of 'Niter' iterations.

x=zeros(1,Niter+1);% Initialize our results vector x by setting it to a bunch of zeros.  
% This isn't necessary, but it allows Matlab to run quicker.
x(1)=x0; % The first entry is our given initial condition.

for i = 2:Niter+1;
    x(i) = mapping(x(i-1));% Record the result of 'Niter' iterations.
end

clf; % Clear any other plots that might be present.
plot([0:Niter],x,'d-'); % Create the time series plot.
xlabel('n','FontSize',14,'FontName','Times') % A series of labelling commands, with some options changed to improve legibility.
ylabel('x_n','FontSize',14,'FontName','Times')
% Note how we automatically insert any of our variables into objects like
% the title of the plot:
title(['x_n for the logistic map for the initial condition x_0 = ' num2str(x0,'%2.2f')],'FontSize',16,'FontName','Times')
set(gca,'FontSize',12,'FontName','Times') % gca is the current figure's axis settings.  This changes the labels on the tick marks.

%---------------------------------------------------------------
function out = mapping(z); % A subfunction that defintes the dynamical mapping function.
out = 3.5.*z.*(1-z);