Public Member Functions | Public Attributes | Protected Member Functions | List of all members
o2scl::deriv_cern< func_t > Class Template Reference

Numerical differentiation routine (CERNLIB) More...

#include <deriv_cern.h>

Inheritance diagram for o2scl::deriv_cern< func_t >:
o2scl::deriv_base< func_t >

Public Member Functions

virtual int deriv_err (double x, 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 ("deriv_cern")
 
- Public Member Functions inherited from o2scl::deriv_base< func_t >
virtual double deriv (double x, func_t &func)
 Calculate the first derivative of func w.r.t. x. More...
 
virtual double deriv2 (double x, func_t &func)
 Calculate the second derivative of func w.r.t. x.
 
virtual double deriv3 (double x, func_t &func)
 Calculate the third derivative of func w.r.t. x.
 
virtual double get_err ()
 Get uncertainty of last calculation.
 
virtual int deriv2_err (double x, func_t &func, double &d2fdx2, double &err)
 Calculate the second derivative of func w.r.t. x and the uncertainty.
 
virtual int deriv3_err (double x, func_t &func, double &d3fdx3, double &err)
 Calculate the third derivative of func w.r.t. x and the uncertainty.
 

Public Attributes

double delta
 A scaling factor (default 1.0)
 
double eps
 Extrapolation tolerance (default is $ 5 \times 10^{14} $)
 
- Public Attributes inherited from o2scl::deriv_base< func_t >
bool err_nonconv
 If true, call the error handler if the routine does not "converge".
 
int verbose
 Output control.
 

Protected Member Functions

template<class func2_t >
int deriv_tlate (double x, func2_t &func, double &dfdx, double &err)
 Internal template version of the derivative function.
 
virtual int deriv_err_int (double x, funct11 &func, double &dfdx, double &err)
 Calculate the first derivative of func w.r.t. x. More...
 
- Protected Member Functions inherited from o2scl::deriv_base< func_t >
virtual double deriv_int (double x, funct11 &func)
 Calculate the first derivative of func w.r.t. x. More...
 
double derivfun (double x, func_t *fp)
 The function for the second derivative.
 
double derivfun2 (double x, func_t *fp)
 The function for the third derivative.
 

Protected Attributes

Storage for the fixed coefficients
double dx [10]
 
double w [10][4]
 
- Protected Attributes inherited from o2scl::deriv_base< func_t >
bool from_deriv
 Avoids infinite loops in case the user calls the base class version.
 
double derr
 The uncertainity in the most recent derivative computation.
 

Detailed Description

template<class func_t = funct11>
class o2scl::deriv_cern< 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_base::verbose is greater than zero, then each iteration prints out the extrapolation table, and if deriv_base::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 Differentiation example .

If deriv_base::verbose is greater than zero, at each iteration this class prints something similar to

deriv_cern, iteration: 1
(hh, a[k], derivative) list: 
-4.193459e-05 4.387643e-14 8.775286e-01
-2.995402e-05 4.387792e-14 8.775585e-01
-1.048405e-05 4.387845e-14 8.775690e-01
-7.488654e-06 4.387882e-14 8.775765e-01
-2.621038e-06 4.387895e-14 8.775791e-01
-1.872173e-06 4.387905e-14 8.775810e-01
-6.552611e-07 4.387908e-14 8.775817e-01
-4.680438e-07 4.387910e-14 8.775821e-01
-1.638153e-07 4.387911e-14 8.775823e-01

If deriv_base::verbose is greater than 1, a keypress is required after each iteration.

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?

Record the number of function calls?

Definition at line 94 of file deriv_cern.h.

Member Function Documentation

◆ deriv_err_int()

template<class func_t = funct11>
virtual int o2scl::deriv_cern< func_t >::deriv_err_int ( double  x,
funct11 func,
double &  dfdx,
double &  err 
)
inlineprotectedvirtual

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

Implements o2scl::deriv_base< func_t >.

Definition at line 253 of file deriv_cern.h.


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

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).