
% Shows that a generic sink attracts orbits lying on its basisn of attraction
% Ricardo Carretero Marcg-2003

f1 = inline('[0.7*(x-1).^3+1+0.2*(x-1)]','x');
f2 = inline('[2*sin(30*(x-1))+3*sin(20.1*(x-1))+1*sin(50.1*(x-1))]','x');

Npts=200;
Nit=7;

x=linspace(0,2,Npts);

fs=15;
lw=2;

x0=input('x0 [1.9] = ');

if(isempty(x0))
 x0=1.9
end

figure(1)
set(gca,'FontSize',[fs]);

plot(1,1,'go','LineWidth',5)
hold on
plot(x,f1(x)+0.03*f2(x+0.01).*(x-1),'b','LineWidth',lw)
plot(x,x,'k')
axis([0 2 0 2])

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

xo=x0;

for i=1:Nit
 xn=f1(xo)+0.03*f2(xo+0.01).*(xo-1);
 X=[X xo xn];
 Y=[Y xn xn];
 xo=xn;
 plot(X,Y,'r','LineWidth',1)
 fprintf('Press any key...\n')
 pause
end


