]> gitweb.michael.orlitzky.com - octave.git/commitdiff
Avoid divide-by-zero in step_length_positive_definite.m.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 23 Mar 2013 02:30:00 +0000 (22:30 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 23 Mar 2013 02:30:00 +0000 (22:30 -0400)
optimization/step_length_positive_definite.m

index ad63956cfa603c097084d15291962c552d6c9d7a..ced556234359ab5bbc3b94d81830176f5551cff4 100644 (file)
@@ -32,5 +32,13 @@ function alpha = step_length_positive_definite(g, Q, p)
   %
   % All vectors are assumed to be *column* vectors.
   %
   %
   % 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
 end