% doubling_map.m
% This script plots a time series and prints out orbits
% for the doubling map defined in section 3.5.      
% Inputs (these can be modified):
%   n is the number of times to iterate F
%   x0 is the initial seed in the orbit (can be a list of different seeds)
% Outputs:
%   a plot of the orbit values (on the y-axis) vs time step (on x-axis)
F = @(x) 2*x.*((x>=0) & (x<1/2)) + (2*x-1).*((x>=1/2) & (x<1));

n = 100;
x0 = [1/5, 1/9]; % list of different seeds
% Main code, need not modify
orbit = zeros(n+1, length(x0));
orbit(1,:) = x0;
for i = 1:n
        orbit(i+1,:) = F(orbit(i, :));
end
% Print out a time series of the orbit
figure(1);
clf();
hold on;
plot(0:n, orbit, '-*', 'LineWidth',2);
title('time series of F')
xlabel('iterate');
ylabel('x-value');
ylim([0 1]);
grid on;

orbit