Class for finding the root of a one dimensional function using the Brent algorithm.
It will use the Brent Method for finding function roots in a given interval. First, a grid search is used to bracket the root value with the a step size = (xmax-xmin)/npx. The step size can be controlled via the SetNpx() function. A default value of npx = 100 is used. The default value con be changed using the static method SetDefaultNpx. If the function is unimodal or if its extrema are far apart, setting the fNpx to a small value speeds the algorithm up many times. Then, Brent's method is applied on the bracketed interval. It will use the Brent Method for finding function roots in a given interval. If the Brent method fails to converge the bracketing is repeated on the latest best estimate of the interval. The procedure is repeated with a maximum value (default =10) which can be set for all BrentRootFinder classes with the method SetDefaultNSearch
This class is implemented from TF1::GetX() method.
Definition at line 51 of file BrentRootFinder.h.
Public Member Functions | |
BrentRootFinder () | |
Default Constructor. | |
~BrentRootFinder () override | |
Default Destructor. | |
int | Iterations () const override |
Return number of iteration used to find minimum. | |
const char * | Name () const override |
Return name of root finder algorithm ("BrentRootFinder"). | |
double | Root () const override |
Returns root value. | |
virtual bool | SetFunction (const ROOT::Math::IGenFunction &, double, double) |
Set function to solve and the interval in where to look for the root. | |
bool | SetFunction (const ROOT::Math::IGenFunction &f, double xlow, double xup) override |
Sets the function for the rest of the algorithms. | |
virtual bool | SetFunction (const ROOT::Math::IGradFunction &, double) |
Set function to solve and the interval in where to look for the root. | |
void | SetLogScan (bool on) |
Set a log grid scan (default is equidistant bins) will work only if xlow > 0. | |
void | SetNpx (int npx) |
Set the number of point used to bracket root using a grid. | |
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). | |
int | Status () const override |
Returns status of last estimate. | |
Public Member Functions inherited from ROOT::Math::IRootFinderMethod | |
IRootFinderMethod () | |
Default Constructor. | |
virtual | ~IRootFinderMethod () |
Default Destructor. | |
virtual int | Iterate () |
This method is implemented only by the GSLRootFinder and GSLRootFinderDeriv classes and will return an error if it's not one of them. | |
Static Public Member Functions | |
static void | SetDefaultNpx (int npx) |
set number of default Npx used at construction time (when SetNpx is not called) Default value is 100 | |
static void | SetDefaultNSearch (int n) |
set number of times the bracketing search in combination with is done to find a good interval Default value is 10 | |
Private Attributes | |
const IGenFunction * | fFunction |
Pointer to the function. | |
bool | fLogScan |
flag to control usage of a log scan | |
int | fNIter |
Number of iterations needed for the last estimation. | |
int | fNpx |
Number of points to bracket root with initial grid (def is 100) | |
double | fRoot |
Current estimation of the function root. | |
int | fStatus |
Status of code of the last estimate. | |
double | fXMax |
Upper bound of the search interval. | |
double | fXMin |
Lower bound of the search interval. | |
#include <Math/BrentRootFinder.h>
ROOT::Math::BrentRootFinder::BrentRootFinder | ( | ) |
Default Constructor.
Definition at line 28 of file BrentRootFinder.cxx.
|
inlineoverride |
Default Destructor.
Definition at line 60 of file BrentRootFinder.h.
|
inlineoverridevirtual |
Return number of iteration used to find minimum.
Reimplemented from ROOT::Math::IRootFinderMethod.
Definition at line 104 of file BrentRootFinder.h.
|
overridevirtual |
Return name of root finder algorithm ("BrentRootFinder").
Implements ROOT::Math::IRootFinderMethod.
Definition at line 62 of file BrentRootFinder.cxx.
|
inlineoverridevirtual |
Returns root value.
Need to call first Solve().
Implements ROOT::Math::IRootFinderMethod.
Definition at line 98 of file BrentRootFinder.h.
|
static |
set number of default Npx used at construction time (when SetNpx is not called) Default value is 100
Definition at line 37 of file BrentRootFinder.cxx.
|
static |
set number of times the bracketing search in combination with is done to find a good interval Default value is 10
Definition at line 39 of file BrentRootFinder.cxx.
|
inlinevirtual |
Set function to solve and the interval in where to look for the root.
@param f Function to be minimized. @param xlow Lower bound of the search interval. @param xup Upper bound of the search interval.
Reimplemented from ROOT::Math::IRootFinderMethod.
Definition at line 53 of file IRootFinderMethod.h.
|
overridevirtual |
Sets the function for the rest of the algorithms.
The parameters set the interval where the root has to be calculated.
Reimplemented from ROOT::Math::IRootFinderMethod.
Definition at line 42 of file BrentRootFinder.cxx.
|
inlinevirtual |
Set function to solve and the interval in where to look for the root.
@param f Function to be minimized. @param xlow Lower bound of the search interval. @param xup Upper bound of the search interval.
Reimplemented from ROOT::Math::IRootFinderMethod.
Definition at line 45 of file IRootFinderMethod.h.
|
inline |
Set a log grid scan (default is equidistant bins) will work only if xlow > 0.
Definition at line 95 of file BrentRootFinder.h.
|
inline |
Set the number of point used to bracket root using a grid.
Definition at line 89 of file BrentRootFinder.h.
|
overridevirtual |
Returns the X value corresponding to the function value fy for (xmin<x<xmax).
Method: First, the grid search is used to bracket the maximum with the step size = (xmax-xmin)/fNpx. This way, the step size can be controlled via the SetNpx() function. If the function is unimodal or if its extrema are far apart, setting the fNpx to a small value speeds the algorithm up many times. Then, Brent's method is applied on the bracketed interval.
@param maxIter maximum number of iterations. @param absTol desired absolute error in the minimum position. @param absTol desired relative error in the minimum position.
Implements ROOT::Math::IRootFinderMethod.
Definition at line 66 of file BrentRootFinder.cxx.
|
inlineoverridevirtual |
Returns status of last estimate.
If = 0 is OK
Implements ROOT::Math::IRootFinderMethod.
Definition at line 101 of file BrentRootFinder.h.
|
private |
Pointer to the function.
Definition at line 124 of file BrentRootFinder.h.
|
private |
flag to control usage of a log scan
Definition at line 125 of file BrentRootFinder.h.
|
private |
Number of iterations needed for the last estimation.
Definition at line 126 of file BrentRootFinder.h.
|
private |
Number of points to bracket root with initial grid (def is 100)
Definition at line 127 of file BrentRootFinder.h.
|
private |
Current estimation of the function root.
Definition at line 131 of file BrentRootFinder.h.
|
private |
Status of code of the last estimate.
Definition at line 128 of file BrentRootFinder.h.
|
private |
Upper bound of the search interval.
Definition at line 130 of file BrentRootFinder.h.
|
private |
Lower bound of the search interval.
Definition at line 129 of file BrentRootFinder.h.