Boost logo

Boost Users :

From: John Maddock (jz.maddock_at_[hidden])
Date: 2019-11-07 18:12:10


On 07/11/2019 12:51, Saurabh T via Boost-users wrote:
> Hi,
>
> I would like a way to bracket the root without having to compute or specify the "rising" flag to "bracket_and_solve_root". Is there a way to edit the bracketing implementation so the user need not specify that option? Thanks,

Not easily, do you really not know whether the function is rising or
falling, and if not how do you know there is a root nearby?

But what I suggest you do is:

Let

f1 = f(guess)

f2 = f(2*guess)

if(f1*f2 < 0) then we have brackets, so call toms748_solve(f, guess,
2*guess...).

if(f1 >0 && f1>f2) then function is falling and guess*2 is better than
guess.  try bracket_and_solve_root with 4*guess as the start point.

if(f1 >0 && f1 < f2) then function is falling and "guess" is better, try
bracket_and_solve_root with guess/2 as the start point.

if(f1 < 0 && f1>f2) then the function is falling and "guess" is better,
try bracket_and_solve_root at guess/2.

otherwise f1 < 0 and f1<f2, then the function is rising and guess*2 is
better, try bracket_and_solve_root at guess*4.

~~~~~~~~~~~~~~~~~~~~~~~

Important: bracket_and_solve_root is a useful shortcut, but it
absolutely will not work if the function is not uniformly rising or
falling.  If the function is oscillatory, or has minima or other problem
issues, then you will need to bracket the root by some other means and
call toms748_solveyourself.

HTH, John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net