bracket_and_solve_root "rising" option
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, saurabh
-----Original Message----- From: Boost-users
On Behalf Of Saurabh T via Boost-users Sent: 7 November 2019 12:51 To: boost-users@lists.boost.org Cc: Saurabh T Subject: [Boost-users] bracket_and_solve_root "rising" option 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,
You could just assume is_rising ==true and see if it converges by testing if iterations >= max_iterations Setting max_iterations to a sensible value (<50) will avoid a long wait 😉 If it doesn't converge, try is_rising = false. Crude and slow? Or you could compute the bounds yourself and use TOMS748 boost/libs/math/doc/html/math_toolkit/roots_noderiv/TOMS748.html but that means more work. Or you could use Brent's algorithm \math\example\brent_minimise_example.cpp, but you still need to provide bracket values, and choosing -infinity and +infinity will not be fast. (Again limiting the number of iterations is wise if you fear a long wait). Fundamentally it is important to provide the algorithm with as much info as possible as a guess, bracket limits, and is rising or falling in order that it works efficiently, or indeed at all. I suspect you do know more really? HTH Paul
Or you could use Brent's algorithm No!! That's not a root finding algorithm, it's function minimization. See https://www.boost.org/doc/libs/1_71_0/libs/math/doc/html/math_toolkit/roots_... \math\example\brent_minimise_example.cpp, but you still need to provide bracket values, and choosing -infinity and +infinity will not be fast. (Again limiting the number of iterations is wise if you fear a long wait).
Fundamentally it is important to provide the algorithm with as much info as possible as a guess, bracket limits, and is rising or falling in order that it works efficiently, or indeed at all.
I suspect you do know more really?
HTH
Paul
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
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
participants (3)
-
John Maddock
-
pbristowï¼ hetp.u-net.com
-
Saurabh T