Thanks, I've committed your patch to the trunk.
> Hi Luigi,
>
> I noticed that a number of the other 1D solvers had the same issue, i.e.,
> the calculation of root_ is fine but the final calculation of the funtion f
> may have been performed with a value different from the return value of
> root_. Hence, if you are using the solver in an iterative routine, the
> underlying results may not be updated with the return value of root_.
>
> The attached file, solvers1d.diff, shows the changes that I made to fix
> this. The files iterativesolvers.xpp give a unit test that exercises the fix
> for the solvers Brent, Newton, NewtonSafe and Ridder. The Bisection method
> passes the test with and without the fix. No changes were made to the Secant
> or False Position method.
> Thanks and regards,
> Francis.
> On Fri, Nov 30, 2012 at 10:48 PM, Francis Duffy <
[hidden email]>
> wrote:
>>
>> Hi Luigi,
>>
>> No problem, I will do that over the coming days and send it to you.
>>
>> Thanks,
>> Francis.
>> On Fri, Nov 30, 2012 at 4:27 PM, Luigi Ballabio <
[hidden email]>
>> wrote:
>>>
>>> Ok. If you have time, could you also write a test case to exercise the
>>> fix?
>>>
>>> Thanks,
>>> Luigi
>>>
>>>
>>> On Fri, Nov 30, 2012 at 4:37 PM, Francis Duffy <
[hidden email]>
>>> wrote:
>>> > Hi Luigi,
>>> >
>>> > Yes, I think so.
>>> >
>>> > Regards,
>>> > Francis.
>>> >
>>> >
>>> > On Fri, Nov 30, 2012 at 2:25 PM, Luigi Ballabio
>>> > <
[hidden email]>
>>> > wrote:
>>> >>
>>> >> Hi Francis,
>>> >> is your patch still needed after the changes?
>>> >>
>>> >> Luigi
>>> >>
>>> >> On Thu, Nov 29, 2012 at 10:44 PM, Francis Duffy
>>> >> <
[hidden email]> wrote:
>>> >> > Hi,
>>> >> >
>>> >> > You are right. This change was made in the HEAD in response to a
>>> >> > query
>>> >> > to
>>> >> > the quantlib-dev group on 26/07/2012. The change is shown below.
>>> >> >
>>> >> > Regards,
>>> >> > Francis.
>>> >> >
>>> >> >>svn diff -r {2012-07-26}:HEAD QuantLib\ql\math\solvers1d\brent.hpp
>>> >> > Index: QuantLib/ql/math/solvers1d/brent.hpp
>>> >> > ===================================================================
>>> >> > --- QuantLib/ql/math/solvers1d/brent.hpp (revision 18300)
>>> >> > +++ QuantLib/ql/math/solvers1d/brent.hpp (revision 18376)
>>> >> > @@ -46,11 +46,22 @@
>>> >> > Real min1, min2;
>>> >> > Real froot, p, q, r, s, xAcc1, xMid;
>>> >> > - // dummy assignements to avoid compiler warning
>>> >> > - Real d = 0.0, e = 0.0;
>>> >> > - root_ = xMax_;
>>> >> > - froot = fxMax_;
>>> >> > + // we want to start with root_ (which equals the guess)
>>> >> > on
>>> >> > + // one side of the bracket and both xMin_ and xMax_ on
>>> >> > the
>>> >> > + // other.
>>> >> > + froot = f(root_);
>>> >> > + ++evaluationNumber_;
>>> >> > + if (froot * fxMin_ < 0) {
>>> >> > + xMax_ = xMin_;
>>> >> > + fxMax_ = fxMin_;
>>> >> > + } else {
>>> >> > + xMin_ = xMax_;
>>> >> > + fxMin_ = fxMax_;
>>> >> > + }
>>> >> > + Real d = root_- xMax_;
>>> >> > + Real e = d;
>>> >> > +
>>> >> > while (evaluationNumber_<=maxEvaluations_) {
>>> >> > if ((froot > 0.0 && fxMax_ > 0.0) ||
>>> >> > (froot < 0.0 && fxMax_ < 0.0)) {
>>> >> >
>>> >> >
>>> >> > On Thu, Nov 29, 2012 at 7:11 PM, cf16r <
[hidden email]> wrote:
>>> >> >>
>>> >> >> additional issue is that Brent method doesn't take in to account
>>> >> >> initial
>>> >> >> guess.
>>> >> >> when you call Brent solveImpl method through solver1d.solve with
>>> >> >> guess
>>> >> >> as
>>> >> >> one of the arguments, root_ is set to this value in solve() but
>>> >> >> just
>>> >> >> after
>>> >> >> entering solveImpl() it is changed back to root_=xMax_ without any
>>> >> >> checking
>>> >> >> whether guess is correct.
>>> >> >> in this scenario I think there is also need to call f(root_) before
>>> >> >> returning solution.
>>> >> >>
>>> >> >> regards,
>>> >> >> cf16
>>> >> >>
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > ------------------------------------------------------------------------------
>>> >> > Keep yourself connected to Go Parallel:
>>> >> > VERIFY Test and improve your parallel project with help from experts
>>> >> > and peers.
http://goparallel.sourceforge.net>>> >> > _______________________________________________
>>> >> > QuantLib-users mailing list
>>> >> >
[hidden email]
>>> >> >
https://lists.sourceforge.net/lists/listinfo/quantlib-users>>> >> >
>>> >
>>> >
>>
>>
>
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Discover what IT Professionals Know. Rescue delivers