| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

Numerical derivative (using GSL adaptive numerical differentiation). More...

`#include <NumericalDerivative.h>`

List of all members.

## Public Types
enum | Type { Central, Forward, Backward }
| the type of numerical differentiation More...
## Public Member Functions
| NumericalDerivative (const AbsFunction &function, const size_t index, const Type &type=Central)
| From CLHEP/GenericFunctions.
| NumericalDerivative (const NumericalDerivative &right)
| copy constructor
virtual | ~NumericalDerivative ()
| virtual 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
size_t | index () const
| index
const Type & | type () const
| type
const Type & | setType (const Type &value)
| change the type of the adaptive differentiation
double | result () const
| the result of the last call
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

## 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.

## 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` |
| ) |  |  |

From CLHEP/GenericFunctions.

from CLHEP/GenericFunctions

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

The standard constructor from AbsFunction and the index of the variable

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]`

virtual destructor

destructor

Definition at line 89 of file NumericalDerivative.cpp.

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

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

## Member Function Documentation

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

dimensionality of the problem

Definition at line 98 of file NumericalDerivative.h.

    00098 { return m_DIM ; }

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

Function value.

Definition at line 164 of file NumericalDerivative.cpp.

    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.

    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.

    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.

    00114 { return *m_function ; }

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

index

Definition at line 116 of file NumericalDerivative.h.

    00116 { return  m_index    ; }

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

type

Definition at line 118 of file NumericalDerivative.h.

    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.

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

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

the result of the last call

Definition at line 124 of file NumericalDerivative.h.

    00124 { return m_result    ; }

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

the absolute error estimate for the last call

Definition at line 126 of file NumericalDerivative.h.

    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.

    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.

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

Definition at line 143 of file NumericalDerivative.h.

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

Definition at line 144 of file NumericalDerivative.h.

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

Definition at line 145 of file NumericalDerivative.h.

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.

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

Definition at line 149 of file NumericalDerivative.h.

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

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