
% Iterated function system
% Ricardo Carretero Mar/03

f1 = inline('[x/3]','x');
f2 = inline('[(2+x)/3]','x');

Npts=1000;
Nit=10;
x=pi/6;		% ICs
ms=3;
fs=15;

figure(1)
clf
axis([0 1 0 1]);
set(gca,'FontSize',[fs]);
xlabel('x_n'); 


p1 = plot(x,0,'r.','EraseMode','none','MarkerSize',ms);
axis([0 1 -0.1 0.1]);

X=[x];

for i=1:Nit
 X1=[];
 for i=1:Npts
  r=rand(1)*2;
  if(r<1)
   F = f1(x);
  else
   F = f2(x);
  end
  x=F(1);
  X1=[X1,x];
 end
 set(p1,'Xdata',X1,'YData',X1*0)
 drawnow;
 X=[X,X1];
end

Ntrans=5;

plot(X,0*X,'r.','EraseMode','none','MarkerSize',ms);
hold on
plot(X(1:1),0*X(1:1),'ko','EraseMode','none','MarkerSize',8);
plot(X(1:Ntrans),0*X(1:Ntrans),'b*','EraseMode','none','MarkerSize',8);

for ii=1:Ntrans
 text(X(ii),-0.1,num2str(ii))
end

drawnow;
hold off

