40 return "ModABRootFinder";
46 return (
x > 0) - (
x < 0);
55 MATH_ERROR_MSG(
"ModABRootFinder::Solve",
"Function has not been set");
58 double x1 =
fXMin, y1 = (*fFunction)(x1);
64 double x2 =
fXMax, y2 = (*fFunction)(x2);
70 if (sign(y1) == sign(y2)) {
71 MATH_ERROR_MSG(
"ModABRootFinder::Solve",
"Function values at the interval endpoints have the same sign");
75 bool bisection =
true;
76 double threshold = x2 - x1;
78 for (
int i = 1; i <= maxIter; ++i) {
82 y3 = (*fFunction)(x3);
83 double ym = (y1 + y2) / 2.0;
84 double r = 1 - std::fabs(ym / (y2 - y1));
86 if (std::fabs(ym - y3) < k * (std::fabs(y3) + std::fabs(ym))) {
88 threshold = (x2 - x1) * C;
91 x3 = (x1 * y2 - y1 * x2) / (y2 - y1);
97 }
else if (x3 >= x2) {
101 y3 = (*fFunction)(x3);
107 double eps = absTol + relTol * std::abs(x3);
108 if (std::fabs(y3) == 0.0 || x2 - x1 <= eps) {
114 double m = 1 - y3 / y1;
119 }
else if (!bisection)
126 double m = 1 - y3 / y2;
131 }
else if (!bisection)
137 if (x2 - x1 > threshold) {
143 MATH_ERROR_MSG(
"ModABRootFinder::Solve",
"Search didn't converge");
#define MATH_ERROR_MSG(loc, str)
const char * Name() const override
Return name of root finder algorithm ("ModABRootFinder").
const IGenFunction * fFunction
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10) override
Returns the X value corresponding to the function value fy for (xmin<x<xmax).
bool SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup) override
Sets the function for the rest of the algorithms.
IBaseFunctionOneDim IGenFunction