function alpha = step_length_positive_definite(g, Q)
  %
  % Find the minimizer alpha of,
  %
  %   phi(alpha) = f(x + alpha*p)
  %
  % where ``p`` is a descent direction,
  %
  %   f(x) = (1/2)<Qx,x> - <b,x>
  %
  % and ``Q`` is positive-definite.
  %
  % The closed-form solution to this problem is given in Nocedal and
  % Wright, (3.55). The direction of steepest descent will always be
  % the negative gradient direction; this simplified form is given in
  % Guler.
  %
  % INPUT:
  %
  %   - ``g`` -- The gradient of f at x.
  %
  %   - ``Q`` -- The positive-definite matrix in the definition of
  %   ``f`` above.
  %
  % OUTPUT:
  %
  %   - ``alpha`` -- The value which decreases ``f`` the most.
  %
  % NOTES:
  %
  % All vectors are assumed to be *column* vectors.
  %
  denom = (g' * Q * g);

  % denom is non-negative, since it's a Q-norm. No need to abs() it.
  if (denom < eps)
    % Catch divide-by-zeros. If denom is effectively zero, set it to
    % something tiny instead. This trick is also used in the PCGM.
    denom = eps;
  end

  alpha = (g' * g)/denom;
end
