diff scripts/optimization/fsolve.m @ 21099:52af4092f863

For optimization scripts, correctly choose tolerance (eps) based on class of fun and X0. * fminbnd.m, fminsearch.m, fminunc.m, fsolve.m: Use 'isa (..., "single")' to check both initial guess X0 and result of function evaluation to decide whether eps should be single or double.
author Rik <rik@octave.org>
date Mon, 18 Jan 2016 10:00:56 -0800
parents 516bb87ea72e
children 3be6a07e8bad
line wrap: on
line diff
--- a/scripts/optimization/fsolve.m	Wed Dec 16 12:09:59 2015 +1100
+++ b/scripts/optimization/fsolve.m	Mon Jan 18 10:00:56 2016 -0800
@@ -185,10 +185,8 @@
     fcn = @(x) guarded_eval (fcn, x, complexeqn);
   endif
 
-  ## These defaults are rather stringent. I think that normally, user
-  ## prefers accuracy to performance.
-
-  macheps = eps (class (x0));
+  ## These defaults are rather stringent.
+  ## Normally user prefers accuracy to performance.
 
   tolx = optimget (options, "TolX", 1e-7);
   tolf = optimget (options, "TolFun", 1e-7);
@@ -223,6 +221,12 @@
     endif
   endif
 
+  if (isa (x0, "single") || isa (fvec, "single"))
+    macheps = eps ("single");
+  else
+    macheps = eps ("double");
+  endif
+
   nsuciter = 0;
 
   ## Outer loop.