X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=optimization%2Fstep_length_positive_definite.m;h=7e15a46513e7333a63f060385f353720745dbc29;hp=ad63956cfa603c097084d15291962c552d6c9d7a;hb=76a7395151d5d93c696bb350d32efd7e0ff28dd8;hpb=b12c6c2a4bf4cef29b2e08b743c92889505c7ed9 diff --git a/optimization/step_length_positive_definite.m b/optimization/step_length_positive_definite.m index ad63956..7e15a46 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