ROOT   Reference Guide
Searching...
No Matches
BrentRootFinder.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: David Gonzalez Maline 01/2008
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2006 CERN *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. * 10 * For the list of contributors see$ROOTSYS/README/CREDITS. *
11 * *
12 **********************************************************************/
13
15//
16// Created by: David Gonzalez Maline : Wed Jan 21 2008
17//
18
19#ifndef ROOT_Math_BrentRootFinder
20#define ROOT_Math_BrentRootFinder
21
22#include "Math/IFunctionfwd.h"
23
25
26namespace ROOT {
27namespace Math {
28
29//___________________________________________________________________________________________
30/**
31 Class for finding the root of a one dimensional function using the Brent algorithm.
32 It will use the Brent Method for finding function roots in a given interval.
33 First, a grid search is used to bracket the root value
34 with the a step size = (xmax-xmin)/npx. The step size
35 can be controlled via the SetNpx() function. A default value of npx = 100 is used.
36 The default value con be changed using the static method SetDefaultNpx.
37 If the function is unimodal or if its extrema are far apart, setting the fNpx to
38 a small value speeds the algorithm up many times.
39 Then, Brent's method is applied on the bracketed interval.
40 It will use the Brent Method for finding function roots in a given interval.
41 If the Brent method fails to converge the bracketing is repeated on the latest best estimate of the
42 interval. The procedure is repeated with a maximum value (default =10) which can be set for all
43 BrentRootFinder classes with the method SetDefaultNSearch
44
45 This class is implemented from TF1::GetX() method.
46
47 @ingroup RootFinders
48
49 */
50
52 public:
53
54
55 /** Default Constructor. */
57
58
59 /** Default Destructor. */
60 ~BrentRootFinder() override {}
61
62
63 /** Set function to solve and the interval in where to look for the root.
64
65 \@param f Function to be minimized.
66 \@param xlow Lower bound of the search interval.
67 \@param xup Upper bound of the search interval.
68 */
70 bool SetFunction(const ROOT::Math::IGenFunction& f, double xlow, double xup) override;
71
72
73 /** Returns the X value corresponding to the function value fy for (xmin<x<xmax).
74 Method:
75 First, the grid search is used to bracket the maximum
76 with the step size = (xmax-xmin)/fNpx. This way, the step size
77 can be controlled via the SetNpx() function. If the function is
78 unimodal or if its extrema are far apart, setting the fNpx to
79 a small value speeds the algorithm up many times.
80 Then, Brent's method is applied on the bracketed interval.
81
82 \@param maxIter maximum number of iterations.
83 \@param absTol desired absolute error in the minimum position.
84 \@param absTol desired relative error in the minimum position.
85 */
86 bool Solve(int maxIter = 100, double absTol = 1E-8, double relTol = 1E-10) override;
87
88 /** Set the number of point used to bracket root using a grid */
89 void SetNpx(int npx) { fNpx = npx; }
90
91 /**
92 Set a log grid scan (default is equidistant bins)
93 will work only if xlow > 0
94 */
95 void SetLogScan(bool on) { fLogScan = on; }
96
97 /** Returns root value. Need to call first Solve(). */
98 double Root() const override { return fRoot; }
99
100 /** Returns status of last estimate. If = 0 is OK */
101 int Status() const override { return fStatus; }
102
103 /** Return number of iteration used to find minimum */
104 int Iterations() const override { return fNIter; }
105
106 /** Return name of root finder algorithm ("BrentRootFinder"). */
107 const char* Name() const override;
108
109 // static function used to modify the default parameters
110
111 /** set number of default Npx used at construction time (when SetNpx is not called)
112 Default value is 100
113 */
114 static void SetDefaultNpx(int npx);
115
116 /** set number of times the bracketing search in combination with is done to find a good interval
117 Default value is 10
118 */
119 static void SetDefaultNSearch(int n);
120
121
122 private:
123
124 const IGenFunction* fFunction; ///< Pointer to the function.
125 bool fLogScan; ///< flag to control usage of a log scan
126 int fNIter; ///< Number of iterations needed for the last estimation.
127 int fNpx; ///< Number of points to bracket root with initial grid (def is 100)
128 int fStatus; ///< Status of code of the last estimate
129 double fXMin; ///< Lower bound of the search interval.
130 double fXMax; ///< Upper bound of the search interval
131 double fRoot; ///< Current estimation of the function root.
132 };
133
134} // namespace Math
135} // namespace ROOT
136
137#endif /* ROOT_Math_BrentRootFinder */
#define f(i)
Definition RSha256.hxx:104
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Class for finding the root of a one dimensional function using the Brent algorithm.
bool SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup) override
Sets the function for the rest of the algorithms.
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).
double fXMin
Lower bound of the search interval.
int Iterations() const override
Return number of iteration used to find minimum.
double fXMax
Upper bound of the search interval.
BrentRootFinder()
Default Constructor.
int fNpx
Number of points to bracket root with initial grid (def is 100)
int fStatus
Status of code of the last estimate.
int fNIter
Number of iterations needed for the last estimation.
double Root() const override
Returns root value.
bool fLogScan
flag to control usage of a log scan
const IGenFunction * fFunction
Pointer to the function.
int Status() const override
Returns status of last estimate.
double fRoot
Current estimation of the function root.
static void SetDefaultNpx(int npx)
set number of default Npx used at construction time (when SetNpx is not called) Default value is 100
const char * Name() const override
Return name of root finder algorithm ("BrentRootFinder").
static void SetDefaultNSearch(int n)
set number of times the bracketing search in combination with is done to find a good interval Default...
void SetNpx(int npx)
Set the number of point used to bracket root using a grid.
void SetLogScan(bool on)
Set a log grid scan (default is equidistant bins) will work only if xlow > 0.
~BrentRootFinder() override
Default Destructor.
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:112
Interface for finding function roots of one-dimensional functions.
virtual bool SetFunction(const ROOT::Math::IGradFunction &, double)
Sets the function for algorithms using derivatives.
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...