
% Demostration of sensitive dependence to ICs.

x=0:0.001:1;
%g = inline('2*x');
%g = inline('4.*x.*(1-x)');
g = inline('mod(3*x,1)');

Npts=10;
%Npts=50;
%Npts=40;


x0=0.012632176524954982
X=[x0];
Y=[0];
xo=x0;

separation=0.00001

x0near=x0+separation
Xnear=[x0near];
Ynear=[0];
xonear=x0near;

index=[];

for i=1:Npts
 index=[index i];
 xn=g(xo);   
 X=[X xo xn];
 Y=[Y xn xn];
 xo=xn;
 xnnear=g(xonear);   
 Xnear=[Xnear xonear xnnear];
 Ynear=[Ynear xnnear xnnear];
 xonear=xnnear;
end

X=X(1:length(X)-1);
Y=Y(1:length(Y)-1);
Xnear=Xnear(1:length(Xnear)-1);
Ynear=Ynear(1:length(Ynear)-1);

figure(1)
clf
set(gca,'FontSize',14)

plot(x,0*x,'k')
hold on
plot(g(x)*0,g(x),'k')
plot(x,x,'k:')
plot(x,g(x),'g','LineWidth',2)
plot(X,Y,'r')
plot(Xnear,Ynear,'b')
axis tight
xlabel('x_n');
ylabel('x_{n+1}');

fprintf('Press any key to continue...');
pause

figure(2)
clf

subplot(3,1,1)
plot(index,Y(1:2:2*Npts),'r')
xlabel('n');ylabel('x_n');
subplot(3,1,2)
plot(index,Ynear(1:2:2*Npts),'b')
xlabel('n');ylabel('x''_n');
subplot(3,1,3)
plot(index,Y(1:2:2*Npts),'r',index,Ynear(1:2:2*Npts),'b')
xlabel('n');ylabel('x_n & x''_n');

