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