function [f, df, H] = test2d(X)
%TEST2D 2D test function for optimisation methods.
%
%       TEST2D is a two dimensional function :
%
%       f(X) = 100*(x2 - 2*sh(x1)/ch(x1)^3)^2 + (1 - x1)^2
%
%       [f df] = TEST2D(X) gives f(X) and df/dX, where X = [x1; x2].
%

MULT = 100 ;
xx = (X(2) - X(1)^3 + X(1)) ;
dx1 = (3*X(1)*X(1) - 1) ;
f = MULT * xx^2 + (1 - X(1))^2 ;

if (nargout > 1)
  df = zeros(size(X)) ;
  df(1) = - 2 * MULT * xx * dx1 - 2*(1 - X(1)) ;
  df(2) = 2 * MULT * xx ;
  if (nargout > 2)
    H = [200*(dx1*dx1 - 6*X(1)*xx) - 2, -2*MULT * dx1 ; ...
         -2*MULT * dx1, 200] ;
  end
end
