cern_deriv Class Template Reference

Numerical differentiation routine (CERNLIB). More...

#include <cern_deriv.h>

Inheritance diagram for cern_deriv:

deriv

Detailed Description

template<class param_t, class func_t = funct<param_t>>
class cern_deriv< param_t, func_t >

This uses Romberg extrapolation to compute the derivative with the finite-differencing formula

\[ f^{\prime}(x) = [f(x+h)-f(x-h)]/(2h) \]

If deriv::verbose is greater than zero, then each iteration prints out the extrapolation table, and if deriv::verbose is greater than 1, then a keypress is required at the end of each iteration.

For sufficiently difficult functions, the derivative computation can fail, and will call the error handler and return zero with zero error.

Based on the CERNLIB routine DERIV, which was based on Rutishauser63 and is documented at http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/d401/top.html

An example demonstrating the usage of this class is given in examples/ex_deriv.cpp and the Numerical differentiation example .

Note:
Second and third derivatives are computed by naive nested applications of the formula for the first derivative. No uncertainty for these derivatives is provided.
Idea for future:
All of the coefficients appear to be fractions which could be replaced with exact representation.

Definition at line 72 of file cern_deriv.h.


Public Member Functions

virtual int calc_err (double x, param_t &pa, func_t &func, double &dfdx, double &err)
 Calculate the first derivative of func w.r.t. x and the uncertainty.
virtual const char * type ()
 Return string denoting type ("cern_deriv").

Data Fields

double delta
 A scaling factor (default 1.0).
double eps
 Extrapolation tolerance (default is $ 5 \times 10^{14} $).

Protected Member Functions

virtual int calc_err_int (double x, typename deriv< param_t, func_t >::dpars &pa, funct< typename deriv< param_t, func_t >::dpars > &func, double &dfdx, double &err)
 Calculate the first derivative of func w.r.t. x.

Protected Attributes

Storage for the fixed coefficients
double dx [10]
double w [10][4]

Member Function Documentation

virtual int calc_err_int ( double  x,
typename deriv< param_t, func_t >::dpars pa,
funct< typename deriv< param_t, func_t >::dpars > &  func,
double &  dfdx,
double &  err 
) [inline, protected, virtual]

This is an internal version of calc() which is used in computing second and third derivatives

Definition at line 225 of file cern_deriv.h.


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

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page