| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

`#include <NumericalDerivative.h>`

List of all members.

## Detailed Description

Numerical derivative (using GSL adaptive numerical differentiation).

Author:
  Vanya BELYAEV Ivan.Belyaev@itep.ru

Date:
  2003-08-27

Definition at line 36 of file NumericalDerivative.h.

## Public Types
enum | Type { Central, Forward, Backward }
| the type of numerical differentiation More...
## Public Member Functions
| FUNCTION_OBJECT_DEF (NumericalDerivative)
| From CLHEP/GenericFunctions.
| NumericalDerivative (const AbsFunction &function, const size_t index, const Type &type=Central)
| The standard constructor from AbsFunction and the index of the variable.
| NumericalDerivative (const NumericalDerivative &right)
| copy constructor
virtual | ~NumericalDerivative ()
| destructor
virtual unsigned int | dimensionality () const
| dimensionality of the problem
virtual double | operator() (double argument) const
| Function value.
virtual double | operator() (const Argument &argument) const
| Function value.
virtual bool | hasAnalyticDerivative () const
| Does this function have an analytic derivative?
virtual Derivative | partial (unsigned int index) const
| Derivatives.
const AbsFunction & | function () const
| access to the function itself
const size_t | index () const
| index
const Type & | type () const
| type
const Type & | setType (const Type &value)
| change the type of the adaptive differentiation
const double | result () const
| the result of the last call
const double | error () const
| the absolute error estimate for the last call
## Protected Member Functions
StatusCode | Exception (const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
| Exception.
## Private Member Functions
| NumericalDerivative ()
NumericalDerivative & | operator= (const NumericalDerivative &)
## Private Attributes
const AbsFunction * | m_function
size_t | m_index
size_t | m_DIM
Type | m_type
Argument | m_argument
double | m_result
double | m_error

## Member Enumeration Documentation

enum Genfun::GaudiMathImplementation::NumericalDerivative::Type

the type of numerical differentiation

Enumerator:

  Central |
  Forward |
  Backward |

Definition at line 40 of file NumericalDerivative.h.

    00041         { Central  ,
    00042           Forward  ,
    00043           Backward } ;

## Constructor & Destructor Documentation

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const AbsFunction & | function,
|  | const size_t | index,
|  | const Type & | type = `Central` |
| ) |  |  |

The standard constructor from AbsFunction and the index of the variable.

The function, created with this constructor compute the numerical derivatived by finite differencing,. An adaptive algorithm is used to find teh best choice of finite difference and to estimate the error in derivative

- The central difference algorithm `gsl_diff_central` is used for `type` = `Type::Central`
- The forward difference algorithm `gsl_diff_forward` is used for `type` = `Type::Forward`. The function is evaluated only at points greater than `x_i` and `x_i` itself. This function should be used if f(x) has a singularity or if it is undefined for values less than `x_i`
- The backward difference algorithm `gsl_diff_backward` is used for `type` = `Type::Backward`. The function is evaluated only at points smaller than `x_i` and `x_i` itself. This function should be used if f(x) has a singularity or if it is undefined for values greater than `x_i`

The adaptime numerical differentiation is used

Parameters:

  | function | the function
  | index | the variable index

Definition at line 53 of file NumericalDerivative.cpp.

    00056       : AbsFunction ()
    00057       , m_function  ( function.clone()          )
    00058       , m_index     ( index                     )
    00059       , m_DIM       ( function.dimensionality() )
    00060       , m_type      ( type                      )
    00061       , m_argument  ( function.dimensionality() )
    00062       , m_result    ( GSL_NEGINF                )
    00063       , m_error     ( GSL_POSINF                )
    00064     {
    00065       if( m_index >= m_DIM )
    00066         { Exception ( "::constructor invalid variable index " ) ; };
    00067     } ;

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const NumericalDerivative & | right | ) |

copy constructor

Definition at line 74 of file NumericalDerivative.cpp.

    00075       : AbsFunction ()
    00076       , m_function  ( right.m_function->clone() )
    00077       , m_index     ( right.m_index             )
    00078       , m_DIM       ( right.m_DIM               )
    00079       , m_type      ( right.m_type              )
    00080       , m_argument  ( right.m_DIM               )
    00081       , m_result    ( GSL_NEGINF                )
    00082       , m_error     ( GSL_POSINF                )
    00083     {} ;

Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative | ( |  | ) | `[virtual]`

destructor

Definition at line 89 of file NumericalDerivative.cpp.

References m_function.

    00090     { if( 0 != m_function ) { delete m_function ; m_function = 0 ; } };

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( |  | ) | `[private]`

Referenced by partial().

## Member Function Documentation

Genfun::GaudiMathImplementation::NumericalDerivative::FUNCTION_OBJECT_DEF | ( | NumericalDerivative |  | ) |

From CLHEP/GenericFunctions.

virtual unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality | ( |  | ) | const`[inline, virtual]`

dimensionality of the problem

Definition at line 98 of file NumericalDerivative.h.

References m_DIM.

    00098 { return m_DIM ; }

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | double | argument | ) | const`[virtual]`

Function value.

Definition at line 164 of file NumericalDerivative.cpp.

References Exception(), m_DIM, m_error, and m_result.

    00165     {
    00166       // reset the result and the error
    00167       m_result = GSL_NEGINF ;
    00168       m_error  = GSL_POSINF ;
    00169
    00170       // check the argument
    00171       if( 1 != m_DIM ) { Exception ( "operator(): invalid argument size " ); }
    00172
    00173       Argument arg(1) ;
    00174       arg[0] = argument ;
    00175       return (*this)( arg ) ;
    00176     };

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | const Argument & | argument | ) | const`[virtual]`

Function value.

copy the argument

use GSL to evaluate the numerical derivative

Definition at line 118 of file NumericalDerivative.cpp.

References Genfun::GaudiMathImplementation::GSL_Adaptor().

    00119     {
    00120       // reset the result and the error
    00121       m_result = GSL_NEGINF ;
    00122       m_error  = GSL_POSINF ;
    00123
    00124       // check the argument
    00125       if( argument.dimension() != m_DIM )
    00126         { Exception ( "::operator():invalid argument size" ) ; };
    00127
    00129       {for( size_t i  = 0 ; i < m_DIM ; ++i ){ m_argument[i] = argument[i];}}
    00130
    00131       // create the helper object
    00132       GSL_Helper helper( *m_function , m_argument , m_index );
    00133
    00135       gsl_function F ;
    00136       F.function = &GSL_Adaptor ;
    00137       F.params   = &helper                 ;
    00138
    00139       double x       = argument[m_index];
    00140       int    ierrno  = 0                   ;
    00141       switch ( type() )
    00142         {
    00143         case Central  :
    00144           ierrno = gsl_diff_central  ( &F , x , &m_result , &m_error ) ; break ;
    00145         case Forward  :
    00146           ierrno = gsl_diff_forward  ( &F , x , &m_result , &m_error ) ; break ;
    00147         case Backward :
    00148           ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
    00149         default:
    00150           Exception ( "::operator(): invalid diffrentiation type " ) ;
    00151         }
    00152
    00153       if( ierrno )
    00154         { gsl_error ( " NumericalDerivative:: the error from gsl_diff_XXXX" ,
    00155                       __FILE__ , __LINE__ , ierrno ) ; }
    00156
    00157       return result() ;
    00158     };

virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative | ( |  | ) | const`[inline, virtual]`

Does this function have an analytic derivative?

Definition at line 106 of file NumericalDerivative.h.

    00106 { return true ;}

Genfun::Derivative Genfun::GaudiMathImplementation::NumericalDerivative::partial | ( | unsigned int | index | ) | const`[virtual]`

Derivatives.

Definition at line 104 of file NumericalDerivative.cpp.

References Exception(), m_DIM, NumericalDerivative(), and type().

    00105     {
    00106       if( idx >= m_DIM )
    00107         { Exception ( "::partial(i): invalid variable index" ) ; }
    00108       const  AbsFunction& aux =
    00109         NumericalDerivative( *this , idx , type() ) ;
    00110       return FunctionNoop( &aux ) ;
    00111     };

const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function | ( |  | ) | const`[inline]`

access to the function itself

Definition at line 114 of file NumericalDerivative.h.

References m_function.

    00114 { return *m_function ; }

const size_t Genfun::GaudiMathImplementation::NumericalDerivative::index | ( |  | ) | const`[inline]`

index

Definition at line 116 of file NumericalDerivative.h.

References m_index.

    00116 { return  m_index    ; }

const Type& Genfun::GaudiMathImplementation::NumericalDerivative::type | ( |  | ) | const`[inline]`

type

Definition at line 118 of file NumericalDerivative.h.

References m_type.

Referenced by partial(), and setType().

    00118 { return  m_type     ; }

const NumericalDerivative::Type & Genfun::GaudiMathImplementation::NumericalDerivative::setType | ( | const Type & | value | ) |

change the type of the adaptive differentiation

Definition at line 97 of file NumericalDerivative.cpp.

References m_type, and type().

    00098     { m_type = value ; return type() ; }

const double Genfun::GaudiMathImplementation::NumericalDerivative::result | ( |  | ) | const`[inline]`

the result of the last call

Definition at line 124 of file NumericalDerivative.h.

References m_result.

    00124 { return m_result    ; }

const double Genfun::GaudiMathImplementation::NumericalDerivative::error | ( |  | ) | const`[inline]`

the absolute error estimate for the last call

Definition at line 126 of file NumericalDerivative.h.

References m_error.

    00126 { return m_error     ; }

StatusCode Genfun::GaudiMathImplementation::NumericalDerivative::Exception | ( | const std::string & | message,
|  | const StatusCode & | sc = `StatusCode::FAILURE` |
| ) |  |  | const`[protected]`

Exception.

Definition at line 183 of file NumericalDerivative.cpp.

Referenced by operator()(), and partial().

    00185     {
    00186       throw GaudiException( "NumericalDerivative" + message ,
    00187                             "*GaudiMath*"         , sc      ) ;
    00188       return sc ;
    00189     };

NumericalDerivative& Genfun::GaudiMathImplementation::NumericalDerivative::operator= | ( | const NumericalDerivative & |  | ) | `[private]`

## Member Data Documentation

const AbsFunction* Genfun::GaudiMathImplementation::NumericalDerivative::m_function`[private]`

Definition at line 142 of file NumericalDerivative.h.

Referenced by function(), and ~NumericalDerivative().

size_t Genfun::GaudiMathImplementation::NumericalDerivative::m_index`[private]`

Definition at line 143 of file NumericalDerivative.h.

Referenced by index().

size_t Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM`[private]`

Definition at line 144 of file NumericalDerivative.h.

Referenced by dimensionality(), operator()(), and partial().

Type Genfun::GaudiMathImplementation::NumericalDerivative::m_type`[private]`

Definition at line 145 of file NumericalDerivative.h.

Referenced by setType(), and type().

Argument Genfun::GaudiMathImplementation::NumericalDerivative::m_argument`[mutable, private]`

Definition at line 147 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_result`[mutable, private]`

Definition at line 148 of file NumericalDerivative.h.

Referenced by operator()(), and result().

double Genfun::GaudiMathImplementation::NumericalDerivative::m_error`[mutable, private]`

Definition at line 149 of file NumericalDerivative.h.

Referenced by error(), and operator()().

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiGSL/v6r9/GaudiMath/NumericalDerivative.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiGSL/v6r9/src/Lib/NumericalDerivative.cpp