ROOT  6.06/09
Reference Guide
MultiNumGradFunction.cxx
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Author: L. Moneta Wed Dec 20 14:36:31 2006
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // implementation file for class MultiNumGradFunction
26 
28 #include <limits>
29 #include <cmath>
30 #include <algorithm> // needed for std::max on Solaris
31 
32 #ifndef ROOT_Math_Derivator
33 #include "Math/Derivator.h"
34 #endif
35 
36 
37 namespace ROOT {
38 
39  namespace Math {
40 
41 
42 double MultiNumGradFunction::fgEps = 0.001;
43 
44 double MultiNumGradFunction::DoDerivative (const double * x, unsigned int icoord ) const {
45  // calculate derivative using mathcore derivator class
46  // step size can be changes using SetDerivPrecision()
47 
48  static double kPrecision = std::sqrt ( std::numeric_limits<double>::epsilon() );
49  double x0 = std::abs(x[icoord]);
50  //double step = (x0 > 0) ? kPrecision * x0 : kPrecision;
51  // this seems to work better than above
52  double step = (x0>0) ? std::max( fgEps* x0, 8.0*kPrecision*(x0 + kPrecision) ) : kPrecision;
53  return ROOT::Math::Derivator::Eval(*fFunc, x, icoord, step);
54 }
55 
57 
59 
60 
61  } // end namespace Math
62 
63 } // end namespace ROOT
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
double Eval(double x, double h=1E-8) const
Computes the numerical derivative of a function f at a point x.
Definition: Derivator.cxx:93
double sqrt(double)
Double_t x[n]
Definition: legend1.C:17
static void SetDerivPrecision(double eps)
precision value used for calculating the derivative step-size h = eps * |x|.
double DoDerivative(const double *x, unsigned int icoord) const
function to evaluate the derivative with respect each coordinate.
static Vc_ALWAYS_INLINE Vector< T > abs(const Vector< T > &x)
Definition: vector.h:450
static double GetDerivPrecision()
get precision value used for calculating the derivative step-size
REAL epsilon
Definition: triangle.c:617
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Namespace for new Math classes and functions.