changeset 25498:68e2daa29222 stable

fsolve.m: exit with info=-2 when singularity reached (bug #53991). * fsolve.m: Check whether the Jacobian is essentially zero, which means the next update would be the same as the existing solution, and exit with info=-2 if found.
author Rik <rik@octave.org>
date Tue, 19 Jun 2018 14:23:16 -0700
parents 0dc3da84ffa3
children c29a2107c559
files scripts/optimization/fsolve.m
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/optimization/fsolve.m	Thu Jun 21 11:05:33 2018 -0400
+++ b/scripts/optimization/fsolve.m	Tue Jun 19 14:23:16 2018 -0700
@@ -304,10 +304,18 @@
 
       ## Get trust-region model (dogleg) minimizer.
       if (useqr)
+        if (norm (r, 1) < macheps * rows (r))
+          info = -2;
+          break;
+        endif
         qtf = q'*fvec;
         s = - __dogleg__ (r, qtf, dg, delta);
         w = qtf + r * s;
       else
+        if (norm (fjac, 1) < macheps * rows (fjac))
+          info = -2;
+          break;
+        endif
         s = - __dogleg__ (fjac, fvec, dg, delta);
         w = fvec + fjac * s;
       endif