Derivator.cxx

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: Derivator.cxx 21114 2007-11-29 17:16:45Z 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 // Implementation file for class GSLDerivator
00026 // 
00027 // Created by: moneta  at Sat Nov 13 14:46:00 2004
00028 // 
00029 // Last update: Sat Nov 13 14:46:00 2004
00030 // 
00031 
00032 #include "Math/IFunction.h"
00033 #include "Math/IParamFunction.h"
00034 #include "Math/Derivator.h"
00035 #include "GSLDerivator.h"
00036 
00037 #include "Math/OneDimFunctionAdapter.h"
00038 
00039 // for GSL greater then 1.5
00040 #include "gsl/gsl_deriv.h"
00041 // for OLD GSL versions
00042 //#include "gsl/gsl_diff.h"
00043 
00044 namespace ROOT {
00045 namespace Math {
00046 
00047 Derivator::Derivator() {
00048    fDerivator = new GSLDerivator();
00049 }
00050    
00051 Derivator::Derivator(const IGenFunction &f) 
00052 {
00053    // allocate a  GSLDerivator
00054    fDerivator = new GSLDerivator();
00055    fDerivator->SetFunction(f);   
00056 }
00057 
00058 Derivator::Derivator(const GSLFuncPointer &f, void * p) 
00059 {
00060    // allocate a GSLDerivator
00061    fDerivator = new GSLDerivator();
00062    fDerivator->SetFunction(f,p);
00063   
00064 }
00065 
00066 Derivator::~Derivator() 
00067 {
00068    if (fDerivator) delete fDerivator;
00069 }
00070 
00071 
00072 Derivator::Derivator(const Derivator &) 
00073 {
00074 }
00075 
00076 Derivator & Derivator::operator = (const Derivator &rhs) 
00077 {
00078    if (this == &rhs) return *this;  // time saving self-test
00079    
00080    return *this;
00081 }
00082 
00083 
00084 void Derivator::SetFunction(const IGenFunction &f) {
00085    fDerivator->SetFunction(f);
00086 }
00087 
00088 void Derivator::SetFunction( const GSLFuncPointer &f, void * p) {
00089    fDerivator->SetFunction(f,p);
00090 }
00091 
00092 
00093 double Derivator::Eval( double x, double h) const { 
00094    return fDerivator->EvalCentral(x, h);
00095 }
00096 
00097 double Derivator::EvalCentral( double x, double h) const { 
00098    return fDerivator->EvalCentral(x, h);
00099 }
00100 
00101 double Derivator::EvalForward( double x, double h) const { 
00102    return fDerivator->EvalForward(x, h);
00103 }
00104 
00105 double Derivator::EvalBackward( double x, double h) const { 
00106    return fDerivator->EvalBackward(x, h);
00107 }
00108 
00109 // static methods 
00110 double Derivator::Eval(const IGenFunction & f, double x, double h ) {
00111    return GSLDerivator::EvalCentral(f, x, h );
00112 }
00113 
00114 double Derivator::EvalCentral(const IGenFunction & f, double x, double h)  {
00115    return GSLDerivator::EvalCentral(f,x,h);
00116 }
00117 
00118 double Derivator::EvalForward(const IGenFunction & f, double x, double h)  {
00119    return GSLDerivator::EvalForward(f, x, h);
00120 } 
00121 
00122 double Derivator::EvalBackward(const IGenFunction & f, double x, double h)  {
00123    return GSLDerivator::EvalBackward(f, x, h);
00124 }
00125 
00126 double Derivator::Eval(const IMultiGenFunction & f, const double * x, unsigned int icoord, double h ) {
00127    // partial derivative for a  multi-dim function
00128    GSLDerivator d; 
00129    OneDimMultiFunctionAdapter<> adapter(f,x,icoord);
00130    d.SetFunction( &GSLFunctionAdapter<OneDimMultiFunctionAdapter<> >::F,static_cast<void *>(&adapter) ); 
00131    return d.EvalCentral(x[icoord],h); 
00132 }
00133 
00134 double Derivator::Eval(IParamFunction & f, double  x, const double * p, unsigned int ipar, double h ) {
00135    // derivative w.r.t parameter  for a one-dim param function
00136    GSLDerivator d; 
00137    const double xx = x; 
00138    OneDimParamFunctionAdapter<IParamFunction &> adapter(f,&xx,p,ipar);
00139    d.SetFunction( &GSLFunctionAdapter<OneDimParamFunctionAdapter<IParamFunction &> >::F,static_cast<void *>(&adapter) ); 
00140    return d.EvalCentral(p[ipar],h); 
00141 }
00142 
00143 double Derivator::Eval(IParamMultiFunction & f, const double * x, const double * p, unsigned int ipar, double h ) {
00144    // derivative w.r.t parameter  for a multi-dim param function
00145    GSLDerivator d; 
00146    OneDimParamFunctionAdapter<IParamMultiFunction &> adapter(f,x,p,ipar);
00147    d.SetFunction( &GSLFunctionAdapter<OneDimParamFunctionAdapter<IParamMultiFunction &> >::F,static_cast<void *>(&adapter) ); 
00148    return d.EvalCentral(p[ipar],h); 
00149 }
00150 
00151 
00152 double Derivator::Result() const { return fDerivator->Result(); }
00153 
00154 double Derivator::Error() const { return fDerivator->Error(); }
00155 
00156 int Derivator::Status() const { return fDerivator->Status(); }
00157 
00158 
00159 
00160 } // namespace Math
00161 } // namespace ROOT

Generated on Tue Jul 5 14:34:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1