Logo ROOT   6.13/01
Reference Guide
Derivator.cxx
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, 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 GSLDerivator
26 //
27 // Created by: moneta at Sat Nov 13 14:46:00 2004
28 //
29 // Last update: Sat Nov 13 14:46:00 2004
30 //
31 
32 #include "Math/IFunction.h"
33 #include "Math/IParamFunction.h"
34 #include "Math/Derivator.h"
35 #include "GSLDerivator.h"
36 
38 
39 // for GSL greater then 1.5
40 #include "gsl/gsl_deriv.h"
41 // for OLD GSL versions
42 //#include "gsl/gsl_diff.h"
43 
44 namespace ROOT {
45 namespace Math {
46 
48  fDerivator = new GSLDerivator();
49 }
50 
52 {
53  // allocate a GSLDerivator
54  fDerivator = new GSLDerivator();
56 }
57 
59 {
60  // allocate a GSLDerivator
61  fDerivator = new GSLDerivator();
62  fDerivator->SetFunction(f,p);
63 
64 }
65 
67 {
68  if (fDerivator) delete fDerivator;
69 }
70 
71 
73 {
74 }
75 
77 {
78  if (this == &rhs) return *this; // time saving self-test
79 
80  return *this;
81 }
82 
83 
86 }
87 
88 void Derivator::SetFunction( const GSLFuncPointer &f, void * p) {
89  fDerivator->SetFunction(f,p);
90 }
91 
92 
93 double Derivator::Eval( double x, double h) const {
94  return fDerivator->EvalCentral(x, h);
95 }
96 
97 double Derivator::EvalCentral( double x, double h) const {
98  return fDerivator->EvalCentral(x, h);
99 }
100 
101 double Derivator::EvalForward( double x, double h) const {
102  return fDerivator->EvalForward(x, h);
103 }
104 
105 double Derivator::EvalBackward( double x, double h) const {
106  return fDerivator->EvalBackward(x, h);
107 }
108 
109 // static methods
110 double Derivator::Eval(const IGenFunction & f, double x, double h ) {
111  return GSLDerivator::EvalCentral(f, x, h );
112 }
113 
114 double Derivator::EvalCentral(const IGenFunction & f, double x, double h) {
115  return GSLDerivator::EvalCentral(f,x,h);
116 }
117 
118 double Derivator::EvalForward(const IGenFunction & f, double x, double h) {
119  return GSLDerivator::EvalForward(f, x, h);
120 }
121 
122 double Derivator::EvalBackward(const IGenFunction & f, double x, double h) {
123  return GSLDerivator::EvalBackward(f, x, h);
124 }
125 
126 double Derivator::Eval(const IMultiGenFunction & f, const double * x, unsigned int icoord, double h ) {
127  // partial derivative for a multi-dim function
128  GSLDerivator d;
129  OneDimMultiFunctionAdapter<> adapter(f,x,icoord);
130  d.SetFunction( &GSLFunctionAdapter<OneDimMultiFunctionAdapter<> >::F,static_cast<void *>(&adapter) );
131  return d.EvalCentral(x[icoord],h);
132 }
133 
134 double Derivator::Eval(IParamFunction & f, double x, const double * p, unsigned int ipar, double h ) {
135  // derivative w.r.t parameter for a one-dim param function
136  GSLDerivator d;
137  const double xx = x;
138  OneDimParamFunctionAdapter<IParamFunction &> adapter(f,&xx,p,ipar);
139  d.SetFunction( &GSLFunctionAdapter<OneDimParamFunctionAdapter<IParamFunction &> >::F,static_cast<void *>(&adapter) );
140  return d.EvalCentral(p[ipar],h);
141 }
142 
143 double Derivator::Eval(IParamMultiFunction & f, const double * x, const double * p, unsigned int ipar, double h ) {
144  // derivative w.r.t parameter for a multi-dim param function
145  GSLDerivator d;
148  return d.EvalCentral(p[ipar],h);
149 }
150 
151 
152 double Derivator::Result() const { return fDerivator->Result(); }
153 
154 double Derivator::Error() const { return fDerivator->Error(); }
155 
156 int Derivator::Status() const { return fDerivator->Status(); }
157 
158 
159 
160 } // namespace Math
161 } // namespace ROOT
double Result() const
return the result of the last derivative calculation
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Class for computing numerical derivative of a function.
Definition: Derivator.h:61
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
double EvalForward(double x, double h)
Computes the numerical derivative at a point x using an adaptive forward difference algorithm with a ...
GSLDerivator * fDerivator
Definition: Derivator.h:232
Derivator & operator=(const Derivator &)
Definition: Derivator.cxx:76
void SetFunction(const IGenFunction &f)
Set the function for calculating the derivatives.
Class for computing numerical derivative of a function based on the GSL numerical algorithm This clas...
Definition: GSLDerivator.h:62
double EvalBackward(double x, double h)
Computes the numerical derivative at a point x using an adaptive backward difference algorithm with a...
double Result() const
return the result of the last derivative calculation
Definition: Derivator.cxx:152
OneDimMultiFunctionAdapter class to wrap a multidimensional function in one dimensional one...
virtual ~Derivator()
destructor
Definition: Derivator.cxx:66
double Error() const
return the estimate of the absolute error of the last derivative calculation
int Status() const
return the error status of the last derivative calculation
Definition: Derivator.cxx:156
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
double EvalCentral(double x, double h=1E-8) const
Computes the numerical derivative at a point x using an adaptive central difference algorithm with a ...
Definition: Derivator.cxx:97
int Status() const
return the error status of the last integral calculation
void SetFunction(const IGenFunction &f)
Set the function for calculating the derivatives.
Definition: Derivator.cxx:84
Class for adapting any C++ functor class to C function pointers used by GSL.
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
OneDimParamFunctionAdapter class to wrap a multi-dim parameteric function in one dimensional one...
* x
Deprecated and error prone model selection interface.
Definition: TRolke.cxx:630
Specialized IParamFunction interface (abstract class) for one-dimensional parametric functions It is ...
Namespace for new Math classes and functions.
double EvalCentral(double x, double h)
Computes the numerical derivative at a point x using an adaptive central difference algorithm with a ...
double EvalForward(double x, double h=1E-8) const
Computes the numerical derivative at a point x using an adaptive forward difference algorithm with a ...
Definition: Derivator.cxx:101
Derivator()
Empty Construct for a Derivator class Need to set the function afterwards with Derivator::SetFunction...
Definition: Derivator.cxx:47
double EvalBackward(double x, double h=1E-8) const
Computes the numerical derivative at a point x using an adaptive backward difference algorithm with a...
Definition: Derivator.cxx:105
double Error() const
return the estimate of the absolute error of the last derivative calculation
Definition: Derivator.cxx:154
double(* GSLFuncPointer)(double, void *)
signature for function pointers used by GSL
Definition: Derivator.h:68