% [f,g] = rosenbrock(x) : evaluate Rosenbrock's function 
% 
% Sven Leyffer, Argonne National Laboratory, 2016
% ------------------------------------------------------
function [f,g,H] = rosenbrock(x)
   f = 100*(x(1)^2 - x(2))^2 + (x(1) - 1)^2;
   if nargout > 1
      g = zeros(2,1);
      g(1) =  400*(x(1)^2 - x(2))*x(1) + 2*(x(1) - 1);
      g(2) = -200*(x(1)^2 - x(2));
   end
   if nargout > 2
      H(1,1) = 400*(x(1)^2 - x(2)) + 800*x(1) + 2;
      H(1,2) = -400*x(1)^2;
      H(2,1) = H(1,2);
      H(2,2) = 200;
   end
