ROOT   Reference Guide
ROOT::Math::RichardsonDerivator Class Reference

User class for calculating the derivatives of a function.

It can calculate first (method Derivative1), second (method Derivative2) and third (method Derivative3) of a function.

It uses the Richardson extrapolation method for function derivation in a given interval. The method use 2 derivative estimates (one computed with step h and one computed with step h/2) to compute a third, more accurate estimation. It is equivalent to the 5-point method, which can be obtained with a Taylor expansion. A step size should be given, depending on x and f(x). An optimal step size value minimizes the truncation error of the expansion and the rounding error in evaluating x+h and f(x+h). A too small h will yield a too large rounding error while a too large h will give a large truncation error in the derivative approximation. A good discussion can be found in discussed in Chapter 5.7 of Numerical Recipes in C. By default a value of 0.001 is uses, acceptable in many cases.

This class is implemented using code previously in TF1::Derivate{,2,3}(). Now TF1 uses this class.

Definition at line 55 of file RichardsonDerivator.h.

## Public Member Functions

RichardsonDerivator (const RichardsonDerivator &rhs)
Copy constructor. More...

RichardsonDerivator (const ROOT::Math::IGenFunction &f, double h=0.001, bool copyFunc=false)
Construct from function and step size. More...

RichardsonDerivator (double h=0.001)
Default Constructor. More...

~RichardsonDerivator ()
Destructor: Removes function if needed. More...

double Derivative1 (const IGenFunction &f, double x, double h)
First Derivative calculation passing function object and step-size. More...

double Derivative1 (double x)
Returns the first derivative of the function at point x, computed by Richardson's extrapolation method (use 2 derivative estimates to compute a third, more accurate estimation) first, derivatives with steps h and h/2 are computed by central difference formulas. More...

double Derivative2 (const IGenFunction &f, double x, double h)
Second Derivative calculation passing function and step-size. More...

double Derivative2 (double x)
Returns the second derivative of the function at point x, computed by Richardson's extrapolation method (use 2 derivative estimates to compute a third, more accurate estimation) first, derivatives with steps h and h/2 are computed by central difference formulas. More...

double Derivative3 (const IGenFunction &f, double x, double h)
Third Derivative calculation passing function and step-size. More...

double Derivative3 (double x)
Returns the third derivative of the function at point x, computed by Richardson's extrapolation method (use 2 derivative estimates to compute a third, more accurate estimation) first, derivatives with steps h and h/2 are computed by central difference formulas. More...

double DerivativeBackward (const IGenFunction &f, double x, double h)
Computation of the first derivative using a forward formula. More...

double DerivativeBackward (double x)
Computation of the first derivative using a backward formula. More...

double DerivativeForward (const IGenFunction &f, double x, double h)
Computation of the first derivative using a forward formula. More...

double DerivativeForward (double x)
Computation of the first derivative using a forward formula. More...

double Error () const
Returns the estimate of the absolute Error of the last derivative calculation. More...

double operator() (double x)

RichardsonDerivatoroperator= (const RichardsonDerivator &rhs)
Assignment operator. More...

void SetFunction (const IGenFunction &f)
Set function for derivative calculation (copy the function if option has been enabled in the constructor) More...

void SetStepSize (double h)
Set step size for derivative calculation. More...

## Protected Attributes

const IGenFunctionfFunction
pointer to function More...

bool fFunctionCopied
flag to control if function is copied in the class More...

double fLastError
error estimate of last derivative calculation More...

double fStepSize
step size used for derivative calculation More...

#include <Math/RichardsonDerivator.h>

## ◆ ~RichardsonDerivator()

 ROOT::Math::RichardsonDerivator::~RichardsonDerivator ( )

Destructor: Removes function if needed.

Definition at line 43 of file RichardsonDerivator.cxx.

## ◆ RichardsonDerivator() [1/3]

 ROOT::Math::RichardsonDerivator::RichardsonDerivator ( double h = 0.001 )

Default Constructor.

Give optionally the step size for derivation. By default is 0.001, which is fine for x ~ 1 Increase if x is in average larger or decrease if x is smaller

Definition at line 23 of file RichardsonDerivator.cxx.

## ◆ RichardsonDerivator() [2/3]

 ROOT::Math::RichardsonDerivator::RichardsonDerivator ( const ROOT::Math::IGenFunction & f, double h = 0.001, bool copyFunc = false )

Construct from function and step size.

Definition at line 31 of file RichardsonDerivator.cxx.

## ◆ RichardsonDerivator() [3/3]

 ROOT::Math::RichardsonDerivator::RichardsonDerivator ( const RichardsonDerivator & rhs )

Copy constructor.

Definition at line 50 of file RichardsonDerivator.cxx.

## ◆ Derivative1() [1/2]

 double ROOT::Math::RichardsonDerivator::Derivative1 ( const IGenFunction & f, double x, double h )

First Derivative calculation passing function object and step-size.

Definition at line 81 of file RichardsonDerivator.cxx.

## ◆ Derivative1() [2/2]

 double ROOT::Math::RichardsonDerivator::Derivative1 ( double x )
inline

Returns the first derivative of the function at point x, computed by Richardson's extrapolation method (use 2 derivative estimates to compute a third, more accurate estimation) first, derivatives with steps h and h/2 are computed by central difference formulas.

$D(h) = \frac{f(x+h) - f(x-h)}{2h}$

the final estimate

$D = \frac{4D(h/2) - D(h)}{3}$

"Numerical Methods for Scientists and Engineers", H.M.Antia, 2nd edition"

the argument eps may be specified to control the step size (precision). the step size is taken as eps*(xmax-xmin). the default value (0.001) should be good enough for the vast majority of functions. Give a smaller value if your function has many changes of the second derivative in the function range.

Getting the error via TF1::DerivativeError: (total error = roundoff error + interpolation error) the estimate of the roundoff error is taken as follows:

$err = k\sqrt{f(x)^{2} + x^{2}deriv^{2}}\sqrt{\sum ai^{2}},$

where k is the double precision, ai are coefficients used in central difference formulas interpolation error is decreased by making the step size h smaller.

Definition at line 116 of file RichardsonDerivator.h.

## ◆ Derivative2() [1/2]

 double ROOT::Math::RichardsonDerivator::Derivative2 ( const IGenFunction & f, double x, double h )

Second Derivative calculation passing function and step-size.

Definition at line 159 of file RichardsonDerivator.cxx.

## ◆ Derivative2() [2/2]

 double ROOT::Math::RichardsonDerivator::Derivative2 ( double x )
inline

Returns the second derivative of the function at point x, computed by Richardson's extrapolation method (use 2 derivative estimates to compute a third, more accurate estimation) first, derivatives with steps h and h/2 are computed by central difference formulas.

$D(h) = \frac{f(x+h) - 2f(x) + f(x-h)}{h^{2}}$

the final estimate

$D = \frac{4D(h/2) - D(h)}{3}$

"Numerical Methods for Scientists and Engineers", H.M.Antia, 2nd edition"

the argument eps may be specified to control the step size (precision). the step size is taken as eps*(xmax-xmin). the default value (0.001) should be good enough for the vast majority of functions. Give a smaller value if your function has many changes of the second derivative in the function range.

Getting the error via TF1::DerivativeError: (total error = roundoff error + interpolation error) the estimate of the roundoff error is taken as follows:

$err = k\sqrt{f(x)^{2} + x^{2}deriv^{2}}\sqrt{\sum ai^{2}},$

where k is the double precision, ai are coefficients used in central difference formulas interpolation error is decreased by making the step size h smaller.

Definition at line 172 of file RichardsonDerivator.h.

## ◆ Derivative3() [1/2]

 double ROOT::Math::RichardsonDerivator::Derivative3 ( const IGenFunction & f, double x, double h )

Third Derivative calculation passing function and step-size.

Definition at line 180 of file RichardsonDerivator.cxx.

## ◆ Derivative3() [2/2]

 double ROOT::Math::RichardsonDerivator::Derivative3 ( double x )
inline

Returns the third derivative of the function at point x, computed by Richardson's extrapolation method (use 2 derivative estimates to compute a third, more accurate estimation) first, derivatives with steps h and h/2 are computed by central difference formulas.

$D(h) = \frac{f(x+2h) - 2f(x+h) + 2f(x-h) - f(x-2h)}{2h^{3}}$

the final estimate

$D = \frac{4D(h/2) - D(h)}{3}$

"Numerical Methods for Scientists and Engineers", H.M.Antia, 2nd edition"

the argument eps may be specified to control the step size (precision). the step size is taken as eps*(xmax-xmin). the default value (0.001) should be good enough for the vast majority of functions. Give a smaller value if your function has many changes of the second derivative in the function range.

Getting the error via TF1::DerivativeError: (total error = roundoff error + interpolation error) the estimate of the roundoff error is taken as follows:

$err = k\sqrt{f(x)^{2} + x^{2}deriv^{2}}\sqrt{\sum ai^{2}},$

where k is the double precision, ai are coefficients used in central difference formulas interpolation error is decreased by making the step size h smaller.

Definition at line 211 of file RichardsonDerivator.h.

## ◆ DerivativeBackward() [1/2]

 double ROOT::Math::RichardsonDerivator::DerivativeBackward ( const IGenFunction & f, double x, double h )
inline

Computation of the first derivative using a forward formula.

Definition at line 138 of file RichardsonDerivator.h.

## ◆ DerivativeBackward() [2/2]

 double ROOT::Math::RichardsonDerivator::DerivativeBackward ( double x )
inline

Computation of the first derivative using a backward formula.

Definition at line 133 of file RichardsonDerivator.h.

## ◆ DerivativeForward() [1/2]

 double ROOT::Math::RichardsonDerivator::DerivativeForward ( const IGenFunction & f, double x, double h )

Computation of the first derivative using a forward formula.

Definition at line 118 of file RichardsonDerivator.cxx.

## ◆ DerivativeForward() [2/2]

 double ROOT::Math::RichardsonDerivator::DerivativeForward ( double x )
inline

Computation of the first derivative using a forward formula.

Definition at line 125 of file RichardsonDerivator.h.

## ◆ Error()

 double ROOT::Math::RichardsonDerivator::Error ( ) const
inline

Returns the estimate of the absolute Error of the last derivative calculation.

Definition at line 83 of file RichardsonDerivator.h.

## ◆ operator()()

 double ROOT::Math::RichardsonDerivator::operator() ( double x )
inline

Definition at line 117 of file RichardsonDerivator.h.

## ◆ operator=()

 RichardsonDerivator & ROOT::Math::RichardsonDerivator::operator= ( const RichardsonDerivator & rhs )

Assignment operator.

Definition at line 60 of file RichardsonDerivator.cxx.

## ◆ SetFunction()

 void ROOT::Math::RichardsonDerivator::SetFunction ( const IGenFunction & f )

Set function for derivative calculation (copy the function if option has been enabled in the constructor)

@param f Function to be differentiated

Definition at line 71 of file RichardsonDerivator.cxx.

## ◆ SetStepSize()

 void ROOT::Math::RichardsonDerivator::SetStepSize ( double h )
inline

Set step size for derivative calculation.

@param h step size for calculation

Definition at line 230 of file RichardsonDerivator.h.

## ◆ fFunction

 const IGenFunction* ROOT::Math::RichardsonDerivator::fFunction
protected

pointer to function

Definition at line 237 of file RichardsonDerivator.h.

## ◆ fFunctionCopied

 bool ROOT::Math::RichardsonDerivator::fFunctionCopied
protected

flag to control if function is copied in the class

Definition at line 234 of file RichardsonDerivator.h.

## ◆ fLastError

 double ROOT::Math::RichardsonDerivator::fLastError
protected

error estimate of last derivative calculation

Definition at line 236 of file RichardsonDerivator.h.

## ◆ fStepSize

 double ROOT::Math::RichardsonDerivator::fStepSize
protected

step size used for derivative calculation

Definition at line 235 of file RichardsonDerivator.h.

Libraries for ROOT::Math::RichardsonDerivator:
[legend]

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