function xx = nlcg (f, df, x0, git, cgit)

  % Nonlinear Gradient/Conjugate Gradient Method

  % For purpose of comvergence comparisons, we have not implemented
  % convergence tests.  We simply iterate in a double loop with
  % git restarts, followed by cgit successive CG steps.

  xnew = x0;
  xx = [xnew];

  for i = 1:git
    x = xnew;
    r = -feval (df, x);
    d = r;
    xnew = dbrent_linesearch (x, d, f, df);
    xx = [xx xnew];
     for j = 1:cgit
      x = xnew;
      rnew = -feval (df, x);
      d = rnew + rnew'*(rnew)/(r'*r)*d;
      r = rnew;
      xnew = dbrent_linesearch (x, d, f, df);
      xx = [xx xnew];
    end
  end

end