From: Michael Orlitzky Date: Sat, 23 Mar 2013 02:30:00 +0000 (-0400) Subject: Avoid divide-by-zero in step_length_positive_definite.m. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=99b1398f7acd8c15e42160c047dcaff816643020;p=octave.git Avoid divide-by-zero in step_length_positive_definite.m. --- diff --git a/optimization/step_length_positive_definite.m b/optimization/step_length_positive_definite.m index ad63956..ced5562 100644 --- a/optimization/step_length_positive_definite.m +++ b/optimization/step_length_positive_definite.m @@ -32,5 +32,13 @@ function alpha = step_length_positive_definite(g, Q, p) % % 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