
% Iterating the Henon map

clear

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

a=input('a [1.4] = ');
b=input('b [0.3] = ');

if(isempty(a))
 a=1.4
end

if(isempty(b))
 b=0.3
end

x0=0.1;
y0=0.2;

Ntransient=1000;
Npts=2000;
Nloops=1000;
fs=15;
ms=1;

X=x0;
Y=y0;
xo=x0;
yo=y0;

ax1=[-2.5 2.5 -2.5 2.5];
ax2=[0.78 0.94 0.78 0.94];
ax3=[0.865 0.895 0.865 0.895];
ax4=[0.881 0.886 0.881 0.886];

b1x=[ax1(1) ax1(2) ax1(2) ax1(1) ax1(1)];
b1y=[ax1(3) ax1(3) ax1(4) ax1(4) ax1(3)];
b2x=[ax2(1) ax2(2) ax2(2) ax2(1) ax2(1)];
b2y=[ax2(3) ax2(3) ax2(4) ax2(4) ax2(3)];
b3x=[ax3(1) ax3(2) ax3(2) ax3(1) ax3(1)];
b3y=[ax3(3) ax3(3) ax3(4) ax3(4) ax3(3)];
b4x=[ax4(1) ax4(2) ax4(2) ax4(1) ax4(1)];
b4y=[ax4(3) ax4(3) ax4(4) ax4(4) ax4(3)];


for i=1:Ntransient
 H=henon_map(a,b,xo,yo);
 xn=H(1);
 yn=H(2);
 X=[X xn];
 Y=[Y yn];
 xo=xn;
 yo=yn;
end

figure(1)
clf

subplot(2,2,1)
plot(b2x,b2y,'b-')
hold on
p1=plot(xo,yo,'r.','EraseMode','none','MarkerSize',ms);
axis(ax1)

subplot(2,2,2)
plot(b3x,b3y,'b-')
hold on
p2=plot(xo,yo,'r.','EraseMode','none','MarkerSize',ms);
axis(ax2)

subplot(2,2,3)
plot(b4x,b4y,'b-')
hold on
p3=plot(xo,yo,'r.','EraseMode','none','MarkerSize',ms);
axis(ax3)

subplot(2,2,4)
p4=plot(xo,yo,'r.','EraseMode','none','MarkerSize',ms);
hold on
axis(ax4)

drawnow

for i=1:Nloops
 X=[];
 Y=[];
 for j=1:Npts
  H=henon_map(a,b,xo,yo);
  xn=H(1);
  yn=H(2);
  X=[X xn];
  Y=[Y yn];
  xo=xn;
  yo=yn;
 end

 subplot(2,2,1)
 set(p1,'Xdata',X,'YData',Y)
 axis(ax1)
 drawnow

 subplot(2,2,2)
 set(p2,'Xdata',X,'YData',Y)
 axis(ax2)
 drawnow

 subplot(2,2,3)
 set(p3,'Xdata',X,'YData',Y)
 axis(ax3)
 drawnow

 subplot(2,2,4)
 set(p4,'Xdata',X,'YData',Y)
 axis(ax4)
 drawnow

% set(gca,'FontSize',[fs]);
% xlabel('x_n'); ylabel('y_n');
% title(['Henon map: a=',num2str(a),', b=',num2str(b),', (x_0,y_0)=(',num2str(x0),',',num2str(y0),')']);

end

