Posted by
Luigi Ballabio on
Apr 30, 2008; 3:47pm
URL: http://quantlib.414.s1.nabble.com/need-help-with-Solver1D-class-tp5976p5977.html
On Wed, 2008-04-30 at 15:30 +0000, Jason Zhang wrote:
> I am quite new with QuantLib and recently I am learning to use the Solver1D
> class. I tried a very simple question of fiding the root to (x^2 + 4x + 4),
> which is -2. The code is very simple to write as follows:
>
> [...]
>
> However, the compilation is okay but it throws exceptions when it runs. What's
> more, if I change the power to 3 (i.e., x^3 + 4x + 4) and it will work and
> give the right answer... It is not only with Brent solver but with other
> solvers as well.
>
> Can someone please let me know what's going wrong? Thanks.
Solvers need a function that crosses the zero---i.e., that goes from
negative to positive values or the other way around. The function you're
using is (x+2)^2, which touches the x-axis at x=-2 but is positive in
any other point. Unfortunately, none of the methods implemented can find
its root (all methods rely on bracketing the root first, i.e., finding
two x1, x2 for which f(x1) < 0 and f(x2) > 0.)
Luigi
--
Westheimer's Discovery:
A couple of months in the laboratory can frequently save a
couple of hours in the library.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users