% STEEPPLOTCONT  Plots the contours of a figure, with the steepest
%                descent iterates
%
%   steepplotcont(f,intx) plots the contours plus the intermediate points
%   intx found by the steepest descent method.
%   Calling sequence: steepplotcont(@f,intx) 
%
%   INPUTS
%   f-> function, see xyfunc for an example.
%   intx-> intermediate values of the steepest descent
%
%
%   Software written by Raf Vandebril
%   Raf.Vandebril-at-cs.kuleuven.be
%   Revision Date: 10/05/2010

function steepplotcont(f,intx);

  % area in the xy-plane is adaptive
  endx=max(abs(intx(1,:))); % Defines begin and end of the figure
  endy=max(abs(intx(2,:)));
  endx=max(endx,1);
  endy=max(endy,1);
  if (endx==0)
    endx=1;
  end
  if (endy==0)
    endy=1;
  end
  

  % Defines the courseness of the grid
  steplength=2*endx/60; 

  % Create the mesh
  [X,Y] = meshgrid(-endx:steplength:endx, -endy:steplength:endy);                                

  % Based on the function f, compute the evaluations in X,Y
  [fxy,grad,Z]=feval(f,0,X,Y);
  
  % Compute the evaluations in Xp,Yp (the intermediate points)
  Xp=intx(1,:);
  Yp=intx(2,:);
  [fxy,grad,Zp]=feval(f,0,Xp,Yp);

  % Plot onto the second figure the contours
  figure(2);
  contour(X,Y,Z);
  hold on
  contour(X,Y,Z,Zp); % the contours touching the points
  plot(Xp,Yp,'b*-','MarkerSize',12); % the points
  hold off
  
