GSLDerivator.cxx

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: GSLDerivator.cxx 20882 2007-11-19 11:31:26Z rdm $
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 "GSLDerivator.h"
00033 
00034 #include "GSLFunctionWrapper.h"
00035 // for GSL greater then 1.5
00036 #include "gsl/gsl_deriv.h"
00037 // for OLD GSL versions
00038 //#include "gsl/gsl_diff.h"
00039 
00040 #include <iostream>
00041 
00042 namespace ROOT {
00043 namespace Math {
00044 
00045 
00046 
00047 double GSLDerivator::EvalCentral( double x, double h) {    
00048    // Central evaluation using previously set function  
00049    if ( !fFunction.IsValid() ) { 
00050       std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
00051       fStatus = -1; 
00052       return 0; 
00053    }
00054    fStatus =  gsl_deriv_central(  fFunction.GetFunc(), x, h, &fResult, &fError); 
00055    return fResult;
00056 }
00057 
00058 double GSLDerivator::EvalForward( double x, double h) {
00059    // Forward evaluation using previously set function  
00060    if ( !fFunction.IsValid() ) { 
00061       std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
00062       fStatus = -1; 
00063       return 0; 
00064    }
00065    fStatus =  gsl_deriv_forward(  fFunction.GetFunc(), x, h, &fResult, &fError); 
00066    return fResult;
00067 }
00068 
00069 double GSLDerivator::EvalBackward( double x, double h) { 
00070    // Backward evaluation using previously set function  
00071    if ( !fFunction.IsValid() ) { 
00072       std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
00073       fStatus = -1; 
00074       return 0; 
00075    }
00076    fStatus =  gsl_deriv_backward(  fFunction.GetFunc(), x, h, &fResult, &fError); 
00077    return fResult;
00078 }
00079 
00080 // static methods not requiring the function
00081 double GSLDerivator::EvalCentral(const IGenFunction & f, double x, double h) { 
00082    // Central evaluation using given function 
00083    GSLFunctionWrapper gslfw; 
00084    double result, error = 0; 
00085    gslfw.SetFunction(f); 
00086    gsl_deriv_central(  gslfw.GetFunc(), x, h, &result, &error);
00087    return result;
00088 }
00089 
00090 double GSLDerivator::EvalForward(const IGenFunction & f, double x, double h) { 
00091    // Forward evaluation using given function 
00092    GSLFunctionWrapper gslfw; 
00093    double result, error = 0; 
00094    gslfw.SetFunction(f); 
00095    gsl_deriv_forward(  gslfw.GetFunc(), x, h, &result, &error);
00096    return result;
00097 }
00098 
00099 double GSLDerivator::EvalBackward(const IGenFunction & f, double x, double h) { 
00100    // Backward evaluation using given function 
00101    GSLFunctionWrapper gslfw; 
00102    double result, error = 0; 
00103    gslfw.SetFunction(f); 
00104    gsl_deriv_backward(  gslfw.GetFunc(), x, h, &result, &error);
00105    return result;
00106 }
00107 
00108 
00109 double GSLDerivator::Result() const { return fResult; }
00110 
00111 double GSLDerivator::Error() const { return fError; }
00112 
00113 int GSLDerivator::Status() const { return fStatus; }
00114 
00115 // fill GSLFunctionWrapper with the pointer to the function
00116 
00117 void  GSLDerivator::SetFunction( GSLFuncPointer  fp, void * p) {  
00118   fFunction.SetFuncPointer( fp ); 
00119   fFunction.SetParams ( p ); 
00120 }
00121 
00122 
00123 void  GSLDerivator::SetFunction(const IGenFunction &f) {  
00124   fFunction.SetFunction(f); 
00125 }
00126 
00127 } // namespace Math
00128 } // namespace ROOT

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