%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pg. 432, <Nonlinear Dynamics and Chaos>, Strogatz %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clf;
clear;
a = 1.4;
b = 0.3;
nplot = 500;

xlast = 0.;
ylast = 0.;
step  = 0;

for step=1:100,
 x = ylast + 1 - a * xlast * xlast;
 y = b * xlast;
 xlast = x;
 ylast = y;
end;

% Now it's absorbed in the attractor:

total_points = 0;
while (1)   
for step=1:nplot,
 x(step) = ylast + 1 - a * xlast * xlast;
 y(step) = b * xlast;
 xlast = x(step);
 ylast = y(step);
end;

plot(x,y,'.');
hold on;

 while(1)
  fprintf(1, 'Continue(left), zoom in (middle), out(right), quit (q)?\n')
  [xnow ynow button] = ginput(1);
  v = axis;
  WINX = v(2)-v(1);
  WINY = v(4)-v(3);

  if (button==1) 
    break;

  elseif (button==2)
%   halve the window;
    axis([xnow-WINX/4 xnow+WINX/4 ynow-WINY/4 ynow+WINY/4]);

  elseif (button==3)
%   double the window;
    axis([xnow-WINX xnow+WINX ynow-WINY ynow+WINY]);

  elseif (button==54)
%   right 
    axis([v(1)+WINX/10 v(2)+WINX/10 v(3) v(4)]);

  elseif (button==52)
%   left 
    axis([v(1)-WINX/10 v(2)-WINX/10 v(3) v(4)]);

  elseif (button==56)
%   up 
    axis([v(1) v(2) v(3)+WINY/10 v(4)+WINY/10]);

  elseif (button==50)
%   down 
    axis([v(1) v(2) v(3)-WINY/10 v(4)-WINY/10]);

  elseif (button==113)
    QUIT = 1;
    break;

  end;
 end;
if (QUIT==1) break; end;
end;

title (['Henon Map: a =' num2str(a), '   b =',num2str(b)]);
xlabel('X');
ylabel('Y');
PRINT;
 