00001 // @(#)root/mathmore:$Id: GSLDerivator.h 35018 2010-08-25 16:40:46Z moneta $ 00002 // Authors: L. Moneta, A. Zsenei 08/2005 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU General Public License * 00010 * as published by the Free Software Foundation; either version 2 * 00011 * of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this library (see file COPYING); if not, write * 00020 * to the Free Software Foundation, Inc., 59 Temple Place, Suite * 00021 * 330, Boston, MA 02111-1307 USA, or contact the author. * 00022 * * 00023 **********************************************************************/ 00024 00025 // Header file for class Derivator 00026 // 00027 // class for calculating Derivative of functions 00028 // 00029 // Created by: moneta at Sat Nov 13 14:46:00 2004 00030 // 00031 // Last update: Sat Nov 13 14:46:00 2004 00032 // 00033 #ifndef ROOT_Math_GSLDerivator 00034 #define ROOT_Math_GSLDerivator 00035 00036 /** 00037 @defgroup Deriv Numerical Differentiation 00038 */ 00039 00040 #include "Math/GSLFunctionAdapter.h" 00041 #include "GSLFunctionWrapper.h" 00042 00043 00044 #include "Math/IFunctionfwd.h" 00045 #include "Math/IFunction.h" 00046 00047 namespace ROOT { 00048 namespace Math { 00049 00050 00051 class GSLFunctionWrapper; 00052 00053 00054 /** 00055 Class for computing numerical derivative of a function based on the GSL numerical algorithm 00056 This class is implemented using the numerical derivatives algorithms provided by GSL 00057 (see <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Numerical-Differentiation.html">GSL Online Manual</A> ). 00058 00059 @ingroup Deriv 00060 */ 00061 00062 class GSLDerivator { 00063 00064 public: 00065 /** 00066 Default Constructor of a GSLDerivator class based on GSL numerical differentiation algorithms 00067 */ 00068 GSLDerivator() : fStatus(0), fResult(0), fError(0) {} 00069 00070 /// destructor (no operations) 00071 virtual ~GSLDerivator() {} 00072 00073 // // disable copying 00074 // private: 00075 00076 // GSLDerivator(const GSLDerivator &); 00077 // GSLDerivator & operator = (const GSLDerivator &); 00078 00079 // public: 00080 00081 00082 00083 /** 00084 Set the function for calculating the derivatives. 00085 The function must implement the ROOT::Math::IGenFunction signature 00086 */ 00087 void SetFunction(const IGenFunction &f); 00088 00089 /** 00090 Set the function f for evaluating the derivative using a GSL function pointer type 00091 @param f : free function pointer of the GSL required type 00092 @param p : pointer to the object carrying the function state 00093 (for example the function object itself) 00094 */ 00095 void SetFunction( GSLFuncPointer f, void * p = 0); 00096 00097 /** 00098 Computes the numerical derivative at a point x using an adaptive central 00099 difference algorithm with a step size h. 00100 */ 00101 double EvalCentral( double x, double h); 00102 00103 /** 00104 Computes the numerical derivative at a point x using an adaptive forward 00105 difference algorithm with a step size h. 00106 The function is evaluated only at points greater than x and at x itself. 00107 */ 00108 double EvalForward( double x, double h); 00109 00110 /** 00111 Computes the numerical derivative at a point x using an adaptive backward 00112 difference algorithm with a step size h. 00113 The function is evaluated only at points less than x and at x itself. 00114 */ 00115 double EvalBackward( double x, double h); 00116 00117 /** @name --- Static methods --- **/ 00118 00119 /** 00120 Computes the numerical derivative of a function f at a point x using an adaptive central 00121 difference algorithm with a step size h 00122 */ 00123 static double EvalCentral(const IGenFunction & f, double x, double h); 00124 00125 00126 /** 00127 Computes the numerical derivative of a function f at a point x using an adaptive forward 00128 difference algorithm with a step size h. 00129 The function is evaluated only at points greater than x and at x itself 00130 */ 00131 static double EvalForward(const IGenFunction & f, double x, double h); 00132 00133 /** 00134 Computes the numerical derivative of a function f at a point x using an adaptive backward 00135 difference algorithm with a step size h. 00136 The function is evaluated only at points less than x and at x itself 00137 */ 00138 00139 static double EvalBackward(const IGenFunction & f, double x, double h); 00140 00141 00142 00143 /** 00144 return the error status of the last integral calculation 00145 */ 00146 int Status() const; 00147 00148 /** 00149 return the result of the last derivative calculation 00150 */ 00151 double Result() const; 00152 00153 /** 00154 return the estimate of the absolute error of the last derivative calculation 00155 */ 00156 double Error() const; 00157 00158 00159 private: 00160 00161 int fStatus; 00162 double fResult; 00163 double fError; 00164 00165 GSLFunctionWrapper fFunction; 00166 00167 }; 00168 00169 00170 00171 00172 } // namespace Math 00173 } // namespace ROOT 00174 00175 00176 #endif /* ROOT_Math_GSLDerivator */