%
% All vectors are assumed to be *column* vectors.
%
- alpha = -(g' * p)/(p' * Q * p);
+ denom = (p' * Q * p);
+
+ if (abs(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 = sign(denom)*eps;
+ end
+
+ alpha = -(g' * p)/denom;
end