# HG changeset patch # User Jaroslav Hajek # Date 1267712363 -3600 # Node ID b4e5dcf023c9bbe154e29624a84fbdea1c94427b # Parent 59e34bcdff134cc01e90a9a41fdcf07fb75e2f5d fix fminbnd termination tolerances diff -r 59e34bcdff13 -r b4e5dcf023c9 scripts/ChangeLog --- a/scripts/ChangeLog Thu Mar 04 09:35:38 2010 +0100 +++ b/scripts/ChangeLog Thu Mar 04 15:19:23 2010 +0100 @@ -1,3 +1,7 @@ +2010-03-04 Jaroslav Hajek + + * optimization/fminbnd.m: Fix termination tolerances. + 2010-03-02 Jaroslav Hajek * polynomial/convn.m: Remove. diff -r 59e34bcdff13 -r b4e5dcf023c9 scripts/optimization/fminbnd.m --- a/scripts/optimization/fminbnd.m Thu Mar 04 09:35:38 2010 +0100 +++ b/scripts/optimization/fminbnd.m Thu Mar 04 15:19:23 2010 +0100 @@ -83,7 +83,7 @@ info = 0; niter = 0; nfev = 0; - eps = eps (class (xmin + xmax)); + sqrteps = eps (class (xmin + xmax)); c = 0.5*(3-sqrt(5)); a = xmin; b = xmax; @@ -95,7 +95,10 @@ while (niter < maxiter && nfev < maxfev) xm = 0.5*(a+b); - tol = 2 * eps * abs (x) + tolx / 3; + ## FIXME: the golden section search can actually get closer than sqrt(eps)... + ## sometimes. Sometimes not, it depends on the function. This is the strategy + ## from the Netlib code. Something yet smarter would be good. + tol = 2 * sqrteps * abs (x) + tolx / 3; if (abs (x - xm) <= (2*tol - 0.5*(b-a))) info = 1; break; @@ -119,7 +122,7 @@ u = x + d; ## f must not be evaluated too close to ax or bx. - if ((u-a) < 2*tol && (b-u) < 2*tol) + if (min (u-a, b-u) < 2*tol) d = tol * (sign (xm - x) + (xm == x)); endif else