% this code looks at sensitivity 
% of iterating on f(x) = 3x(mod1)

x0 = 0.1;
eps = 1e-15;

f= @(x) mod(3*x,1);


N = 3000;
x = zeros(1, N+1);         % 1-by-(N+1) sized list to store the history of x
xeps = zeros(1,N+1);
x(1) = x0;                % put starting value in first element of list
xeps(1) = x0+eps;
y =zeros(size(x));
y(1)= eps;
for i = 1:N
    x(i+1) = f(x(i));
    xeps(i+1) = f(xeps(i));
    y(i+1) = f(y(i));
end
figure(1)
plot(abs(x-xeps),'.')


figure(2)
plot(y,'r.')
    