Boost logo

Boost-Commit :

From: john_at_[hidden]
Date: 2007-09-15 07:19:22


Author: johnmaddock
Date: 2007-09-15 07:19:20 EDT (Sat, 15 Sep 2007)
New Revision: 39296
URL: http://svn.boost.org/trac/boost/changeset/39296

Log:
Fix for failing example: added heuristic to up the multiplication factor if we don't bracket the root quickly.
Text files modified:
   sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp | 20 +++++++++++++++++++-
   1 files changed, 19 insertions(+), 1 deletions(-)

Modified: sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp
==============================================================================
--- sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp (original)
+++ sandbox/math_toolkit/boost/math/tools/toms748_solve.hpp 2007-09-15 07:19:20 EDT (Sat, 15 Sep 2007)
@@ -472,7 +472,7 @@
 }
 
 template <class F, class T, class Tol, class Policy>
-std::pair<T, T> bracket_and_solve_root(F f, const T& guess, const T& factor, bool rising, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
+std::pair<T, T> bracket_and_solve_root(F f, const T& guess, T factor, bool rising, Tol tol, boost::uintmax_t& max_iter, const Policy& pol)
 {
    BOOST_MATH_STD_USING
    static const char* function = "boost::math::tools::bracket_and_solve_root<%1%>";
@@ -498,6 +498,15 @@
       {
          if(count == 0)
             policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", b, pol);
+ //
+ // Heuristic: every 20 iterations we double the growth factor in case the
+ // initial guess was *really* bad !
+ //
+ if((max_iter - count) % 20 == 0)
+ factor *= 2;
+ //
+ // Now go ahead and move are guess by "factor":
+ //
          a = b;
          fa = fb;
          b *= factor;
@@ -523,6 +532,15 @@
          }
          if(count == 0)
             policies::raise_evaluation_error(function, "Unable to bracket root, last nearest value was %1%", a, pol);
+ //
+ // Heuristic: every 20 iterations we double the growth factor in case the
+ // initial guess was *really* bad !
+ //
+ if((max_iter - count) % 20 == 0)
+ factor *= 2;
+ //
+ // Now go ahead and move are guess by "factor":
+ //
          b = a;
          fb = fa;
          a /= factor;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk