Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::Math::BrentRootFinder Class Reference

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 62 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 IGenFunctionfFunction
 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>

Inheritance diagram for ROOT::Math::BrentRootFinder:
[legend]

Constructor & Destructor Documentation

◆ BrentRootFinder()

ROOT::Math::BrentRootFinder::BrentRootFinder ( )

Default Constructor.

Definition at line 25 of file BrentRootFinder.cxx.

◆ ~BrentRootFinder()

ROOT::Math::BrentRootFinder::~BrentRootFinder ( )
inlineoverride

Default Destructor.

Definition at line 71 of file BrentRootFinder.h.

Member Function Documentation

◆ Iterations()

int ROOT::Math::BrentRootFinder::Iterations ( ) const
inlineoverridevirtual

Return number of iteration used to find minimum.

Reimplemented from ROOT::Math::IRootFinderMethod.

Definition at line 115 of file BrentRootFinder.h.

◆ Name()

const char * ROOT::Math::BrentRootFinder::Name ( ) const
overridevirtual

Return name of root finder algorithm ("BrentRootFinder").

Implements ROOT::Math::IRootFinderMethod.

Definition at line 59 of file BrentRootFinder.cxx.

◆ Root()

double ROOT::Math::BrentRootFinder::Root ( ) const
inlineoverridevirtual

Returns root value.

Need to call first Solve().

Implements ROOT::Math::IRootFinderMethod.

Definition at line 109 of file BrentRootFinder.h.

◆ SetDefaultNpx()

void ROOT::Math::BrentRootFinder::SetDefaultNpx ( int  npx)
static

set number of default Npx used at construction time (when SetNpx is not called) Default value is 100

Definition at line 34 of file BrentRootFinder.cxx.

◆ SetDefaultNSearch()

void ROOT::Math::BrentRootFinder::SetDefaultNSearch ( int  n)
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 36 of file BrentRootFinder.cxx.

◆ SetFunction() [1/3]

virtual bool ROOT::Math::IRootFinderMethod::SetFunction ( const ROOT::Math::IGenFunction ,
double  ,
double   
)
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.

◆ SetFunction() [2/3]

bool ROOT::Math::BrentRootFinder::SetFunction ( const ROOT::Math::IGenFunction ,
double  ,
double   
)
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 39 of file BrentRootFinder.cxx.

◆ SetFunction() [3/3]

virtual bool ROOT::Math::IRootFinderMethod::SetFunction ( const ROOT::Math::IGradFunction ,
double   
)
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.

◆ SetLogScan()

void ROOT::Math::BrentRootFinder::SetLogScan ( bool  on)
inline

Set a log grid scan (default is equidistant bins) will work only if xlow > 0.

Definition at line 106 of file BrentRootFinder.h.

◆ SetNpx()

void ROOT::Math::BrentRootFinder::SetNpx ( int  npx)
inline

Set the number of point used to bracket root using a grid.

Definition at line 100 of file BrentRootFinder.h.

◆ Solve()

bool ROOT::Math::BrentRootFinder::Solve ( int  maxIter = 100,
double  absTol = 1E-8,
double  relTol = 1E-10 
)
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 63 of file BrentRootFinder.cxx.

◆ Status()

int ROOT::Math::BrentRootFinder::Status ( ) const
inlineoverridevirtual

Returns status of last estimate.

If = 0 is OK

Implements ROOT::Math::IRootFinderMethod.

Definition at line 112 of file BrentRootFinder.h.

Member Data Documentation

◆ fFunction

const IGenFunction* ROOT::Math::BrentRootFinder::fFunction
private

Pointer to the function.

Definition at line 135 of file BrentRootFinder.h.

◆ fLogScan

bool ROOT::Math::BrentRootFinder::fLogScan
private

flag to control usage of a log scan

Definition at line 136 of file BrentRootFinder.h.

◆ fNIter

int ROOT::Math::BrentRootFinder::fNIter
private

Number of iterations needed for the last estimation.

Definition at line 137 of file BrentRootFinder.h.

◆ fNpx

int ROOT::Math::BrentRootFinder::fNpx
private

Number of points to bracket root with initial grid (def is 100)

Definition at line 138 of file BrentRootFinder.h.

◆ fRoot

double ROOT::Math::BrentRootFinder::fRoot
private

Current estimation of the function root.

Definition at line 142 of file BrentRootFinder.h.

◆ fStatus

int ROOT::Math::BrentRootFinder::fStatus
private

Status of code of the last estimate.

Definition at line 139 of file BrentRootFinder.h.

◆ fXMax

double ROOT::Math::BrentRootFinder::fXMax
private

Upper bound of the search interval.

Definition at line 141 of file BrentRootFinder.h.

◆ fXMin

double ROOT::Math::BrentRootFinder::fXMin
private

Lower bound of the search interval.

Definition at line 140 of file BrentRootFinder.h.

Libraries for ROOT::Math::BrentRootFinder:

The documentation for this class was generated from the following files: