25namespace BrentMethods {
49 bool foundInterval = (
type != 4);
51 yymin = (*function)(xxmin);
53 yymin = -(*function)(xxmin);
55 yymin = (*function)(xxmin)-fy;
64 for (
int i=1; i<=npx-1; i++) {
65 double x =
xmin + i*dx;
73 y = (*function)(
x)-fy;
75 if (
type < 4 &&
y < yymin) {
90 if (std::copysign(1.,
y)*std::copysign(1.,yymin) < 0 ) {
110 xmiddle = std::min(xxmin,
xmax);
114 if (!foundInterval) {
115 MATH_INFO_MSG(
"BrentMethods::MinimStep",
"Grid search failed to find a root in the interval ");
116 std::cout <<
"xmin = " <<
xmin <<
" xmax = " <<
xmax <<
" npts = " << npx << std::endl;
125 double MinimBrent(
const IGenFunction*
function,
int type,
double &
xmin,
double &
xmax,
double xmiddle,
double fy,
bool &ok,
int &niter,
double epsabs,
double epsrel,
int itermax)
141 const double c = 3.81966011250105097e-01;
142 double u,
v, w,
x, fv, fu, fw, fx,
e, p,
q,
r, t2,
d=0,
m, tol;
149 fv = fw = fx = (*function)(
x);
151 fv = fw = fx = -(*function)(
x);
155 for (
int i=0; i<itermax; i++){
176 p = (
x-
v)*
q - (
x-w)*
r;
194 if (u-
a < t2 ||
b-u < t2)
206 fu = -(*function)(u);
213 v=w; fv=fw; w=
x; fw=fx;
x=u; fx=fu;
218 v=w; fv=fw; w=u; fw=fu;
220 else if (fu<=fv ||
v==
x ||
v==w){
#define MATH_INFO_MSG(loc, str)
Pre-processor macro to report messages which can be configured to use ROOT error or simply an std::io...
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Namespace for new Math classes and functions.
double MinimStep(const IGenFunction *f, int type, double &xmin, double &xmax, double fy, int npx=100, bool useLog=false)
Grid search implementation, used to bracket the minimum and later use Brent's method with the bracket...
double MinimBrent(const IGenFunction *f, int type, double &xmin, double &xmax, double xmiddle, double fy, bool &ok, int &niter, double epsabs=1.E-8, double epsrel=1.E-10, int maxiter=100)
Finds a minimum of a function, if the function is unimodal between xmin and xmax This method uses a c...
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)