

% Trapping region for the Henon map (fig 6.7)

clear
format compact

henon_map = inline('[a-x.^2+b*y x]','a','b','x','y');

a=1.4
b=0.3
Nit=3;

Rx=[-1.535 1.742 1.867 -1.88]';
Ry=[-2.05 -0.74 0.71 1.95]';

Rx=[Rx;Rx(1)];
Ry=[Ry;Ry(1)];


L1x=linspace(Rx(1),Rx(2),1000);
L2x=linspace(Rx(2),Rx(3),1000);
L3x=linspace(Rx(3),Rx(4),1000);
L4x=linspace(Rx(4),Rx(5),1000);

L1y=linspace(Ry(1),Ry(2),1000);
L2y=linspace(Ry(2),Ry(3),1000);
L3y=linspace(Ry(3),Ry(4),1000);
L4y=linspace(Ry(4),Ry(5),1000);

Lx=[L1x L2x L3x L4x]';
Ly=[L1y L2y L3y L4y]';

figure(1)
clf
figure(2)
clf
lw=3;
ms=1;

X0=[0.43 0.99];
XX=[];
YY=[];
for j=1:2000
 X0=henon_map(a,b,X0(1),X0(2));
 XX=[XX X0(1)];
 YY=[YY X0(2)];
end

figure(1)
plot(XX,YY,'.','MarkerSize',ms)
hold on
axis([-2.1 2.1 -2.1 2.1]);
set(gca,'FontSize',[18]);
xlabel('x_n'); ylabel('y_n');
title(['Trapping region for Henon map: a=',num2str(a),', b=',num2str(b)])

tnp=4;
np=0;
figure(2)
np=np+1;
subplot(tnp,1,np)
plot(XX,YY,'.','MarkerSize',ms)
hold on
axis([-2.1 2.1 -2.1 2.1]);

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

figure(1)
plot(Lx,Ly,'b','LineWidth',lw)
plot(Rx(1),Ry(1),'mo',Rx(2),Ry(2),'bo',Rx(3),Ry(3),'ko',Rx(4),Ry(4),'go','LineWidth',lw)

figure(2)
%np=np+1;
subplot(tnp,1,np)
plot(Lx,Ly,'b','LineWidth',lw)
hold on
plot(Rx(1),Ry(1),'mo',Rx(2),Ry(2),'bo',Rx(3),Ry(3),'ko',Rx(4),Ry(4),'go','LineWidth',lw)
axis tight

for i=1:Nit
 fprintf('Press any key to continue...\n');
 pause
 H=henon_map(a,b,Rx,Ry);
 Rx=H(:,1);
 Ry=H(:,2);
 H=henon_map(a,b,Lx,Ly);
 Lx=H(:,1);
 Ly=H(:,2);
 if lw>1  
%  lw=lw-1;
  lw=lw-0.5;
 end
 if(i==1)
  figure(1)
  plot(Lx,Ly,'r','LineWidth',lw)
  figure(2)
  np=np+1;
  subplot(tnp,1,np)
  plot(Lx,Ly,'r','LineWidth',lw)
  hold on
 elseif(i==2)
  figure(1)
  plot(Lx,Ly,'Color',[0 0.6 0],'LineWidth',lw)
  figure(2)
  np=np+1;
  subplot(tnp,1,np)
  plot(Lx,Ly,'Color',[0 0.6 0],'LineWidth',lw)
  hold on
 elseif(i==3)
  figure(1)
  plot(Lx,Ly,'m','LineWidth',lw)
  hold on
  figure(2)
  np=np+1;
  subplot(tnp,1,np)
  plot(Lx,Ly,'m','LineWidth',lw)
  hold on
 end
 figure(1)
 plot(Rx(1),Ry(1),'mo',Rx(2),Ry(2),'bo',Rx(3),Ry(3),'ko',Rx(4),Ry(4),'go','LineWidth',lw)
 figure(2)
 subplot(tnp,1,np)
 plot(Rx(1),Ry(1),'mo',Rx(2),Ry(2),'bo',Rx(3),Ry(3),'ko',Rx(4),Ry(4),'go','LineWidth',lw)
 axis tight
end

