protected override double solveImpl(ISolver1d f, double xAccuracy)
{
/* The implementation of the algorithm was inspired by
Press, Teukolsky, Vetterling, and Flannery,
"Numerical Recipes in C", 2nd edition, Cambridge
University Press
*/
double dx, xMid, fMid;
// Orient the search so that f>0 lies at root_+dx
if (fxMin_ < 0.0) {
dx = xMax_-xMin_;
root_ = xMin_;
} else {
dx = xMin_-xMax_;
root_ = xMax_;
}
while (evaluationNumber_ <= maxEvaluations_) {
dx /= 2.0;
xMid = root_ + dx;
fMid = f.value(xMid);
evaluationNumber_++;
if (fMid <= 0.0)
root_ = xMid;
if (Math.Abs(dx) < xAccuracy || fMid == 0.0) {
return root_;
}
}
throw new ArgumentException("maximum number of function evaluations (" + maxEvaluations_ + ") exceeded");
}