function f = extended_rosenbrock1(x)
  %
  % The extended Rosenbrock function. See Dennis & Schnabel, Appendix
  % B, problem #1.
  %
  % This function has a minimum at x=(1,1,...,1) with f(x) == 0. The
  % suggested starting point is x0=(-1.2, 1,-1.2, 1,...,-1.2, 1).
  % Since the number of arguments is variable, we take a vector
  % instead of its individual components.
  %
  n = length(x);

  if (odd(n))
    % 'm' below must be an integer.
    f = NA;
    return;
  end

  m = n / 2;
  f = 0;

  % The extended Rosenbrock is simply a sum of Rosenbrock
  % applications.
  for k = [ 1 : m ]
    y1 = x(2*k - 1);
    y2 = x(2*k);
    f_k = rosenbrock(y1, y2);
    f = f + f_k;
  end
end
