Class deriv_base (o2scl)

O2scl : Class List

template<class func_t = funct, class fp_t = double>
class deriv_base

Numerical differentiation base [abstract base].

This base class does not perform any actual differentiation. Use one of the children o2scl::deriv_cern, o2scl::deriv_gsl, or o2scl::deriv_eqi instead.

This base class contains some code to automatically apply the first derivative routines to compute second or third derivatives. The error estimates for these will likely be underestimated.

Idea for Future:

Improve the methods for second and third derivatives

Note

Because this class template aims to automatically provide second and third derivatives, one must overload either both deriv() and deriv_int() or both deriv_err() and deriv_err_int().

Note

If err_nonconv is set to false, and the derivative computation fails, then the functions deriv(), deriv2() and deriv3() may return the wrong result without warning. Similarly, if err_nonconv is set to false, it is the user’s responsibility to check the return value from deriv_err(), deriv2_err(), and deriv3_err() to see if an error occurred.

Subclassed by o2scl::deriv_cern< func_t >, o2scl::deriv_eqi< func_t, vec_t >, o2scl::deriv_gsl< func_t, fp_t >

Public Functions

inline deriv_base()
inline virtual ~deriv_base()
inline virtual fp_t deriv(fp_t x, func_t &func)

Calculate the first derivative of func w.r.t. x.

After calling deriv(), the error may be obtained from get_err().

inline virtual fp_t deriv2(fp_t x, func_t &func)

Calculate the second derivative of func w.r.t. x.

inline virtual fp_t deriv3(fp_t x, func_t &func)

Calculate the third derivative of func w.r.t. x.

inline virtual fp_t get_err()

Get uncertainty of last calculation.

virtual int deriv_err(fp_t x, func_t &func, fp_t &dfdx, fp_t &err) = 0

Calculate the first derivative of func w.r.t. x and the uncertainty.

inline virtual int deriv2_err(fp_t x, func_t &func, fp_t &d2fdx2, fp_t &err)

Calculate the second derivative of func w.r.t. x and the uncertainty.

inline virtual int deriv3_err(fp_t x, func_t &func, fp_t &d3fdx3, fp_t &err)

Calculate the third derivative of func w.r.t. x and the uncertainty.

inline virtual const char *type()

Return string denoting type (“deriv”)

Public Members

bool err_nonconv

If true, call the error handler if the routine does not “converge”.

int verbose

Output control.

Protected Types

typedef struct o2scl::deriv_base::dpars_s dpars

A structure for passing the function to second and third derivatives [protected].

typedef std::function<fp_t(fp_t)> internal_func_t

Protected Functions

inline virtual fp_t deriv_int(fp_t x, internal_func_t &func)

Calculate the first derivative of func w.r.t. x.

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

virtual int deriv_err_int(fp_t x, internal_func_t &func, fp_t &dfdx, fp_t &err) = 0

Calculate the first derivative of func w.r.t. x and the uncertainty.

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

inline fp_t derivfun(fp_t x, func_t *fp)

The function for the second derivative.

inline fp_t derivfun2(fp_t x, func_t *fp)

The function for the third derivative.

Protected Attributes

bool from_deriv

Avoids infinite loops in case the user calls the base class version.

fp_t derr

The uncertainity in the most recent derivative computation.

struct dpars_s

A structure for passing the function to second and third derivatives [protected].

Public Members

func_t *func

The pointer to the function.