Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches

Parametric Function class describing polynomials of order n.

P(x) = p[0] + p[1]*x + p[2]*x**2 + ....... + p[n]*x**n

The class implements also the derivatives, dP(x)/dx and the dP(x)/dp[i].

The class provides also the method to find the roots of the polynomial. It uses analytical methods up to quartic polynomials.

Implements both the Parameteric function interface and the gradient interface since it provides the analytical gradient with respect to x

Definition at line 64 of file Polynomial.h.

Public Types

typedef ParamFunction< IParamGradFunctionParFunc
 
- Public Types inherited from ROOT::Math::ParamFunction< IParamGradFunction >
typedef IPFType::BaseFunc BaseFunc
 
typedef IParamGradFunction BaseParFunc
 
- Public Types inherited from ROOT::Math::IParametricGradFunctionOneDim
typedef IParametricFunctionOneDim::BaseFunc BaseFunc
 
typedef IGradientFunctionOneDim BaseGradFunc
 
typedef IParametricFunctionOneDim BaseParamFunc
 
- Public Types inherited from ROOT::Math::IParametricFunctionOneDim
typedef IBaseFunctionOneDim BaseFunc
 
- Public Types inherited from ROOT::Math::IBaseFunctionOneDim
typedef IBaseFunctionOneDim BaseFunc
 
- Public Types inherited from ROOT::Math::IGradientFunctionOneDim
typedef IBaseFunctionOneDim BaseFunc
 
typedef IGradientFunctionOneDim BaseGrad
 

Public Member Functions

 Polynomial (double a, double b)
 Construct a Polynomial of degree 1 : a*x + b.
 
 Polynomial (double a, double b, double c)
 Construct a Polynomial of degree 2 : a*x**2 + b*x + c.
 
 Polynomial (double a, double b, double c, double d)
 Construct a Polynomial of degree 3 : a*x**3 + b*x**2 + c*x + d.
 
 Polynomial (double a, double b, double c, double d, double e)
 Construct a Polynomial of degree 4 : a*x**4 + b*x**3 + c*x**2 + dx + e.
 
 Polynomial (unsigned int n=0)
 Construct a Polynomial function of order n.
 
 ~Polynomial () override
 
IGenFunctionClone () const override
 Clone a function.
 
void FdF (double x, double &f, double &df) const override
 Optimized method to evaluate at the same time the function value and derivative at a point x.
 
const std::vector< std::complex< double > > & FindNumRoots ()
 Find the polynomial roots using always an iterative numerical methods The numerical method used is from GSL (see documentation )
 
std::vector< doubleFindRealRoots ()
 Find the only the real polynomial roots.
 
const std::vector< std::complex< double > > & FindRoots ()
 Find the polynomial roots.
 
unsigned int Order () const
 Order of Polynomial.
 
- Public Member Functions inherited from ROOT::Math::ParamFunction< IParamGradFunction >
 ParamFunction (unsigned int npar=0)
 Construct a parameteric function with npar parameters.
 
virtual ~ParamFunction ()
 
unsigned int NPar () const
 Return the number of parameters.
 
virtual const doubleParameters () const
 Access the parameter values.
 
virtual void SetParameters (const double *p)
 Set the parameter values.
 
- Public Member Functions inherited from ROOT::Math::IParametricGradFunctionOneDim
 ~IParametricGradFunctionOneDim () override
 Virtual Destructor (no operations)
 
double ParameterDerivative (const double *x, const double *p, unsigned int ipar=0) const
 Partial derivative with respect a parameter Compatibility interface with multi-dimensional functions.
 
double ParameterDerivative (const double *x, unsigned int ipar=0) const
 Evaluate partial derivative using cached parameter values (multi-dim like interface)
 
double ParameterDerivative (double x, const double *p, unsigned int ipar=0) const
 Partial derivative with respect a parameter.
 
double ParameterDerivative (double x, unsigned int ipar=0) const
 Evaluate partial derivative using cached parameter values.
 
void ParameterGradient (const double *x, const double *p, double *grad) const
 Compatibility interface with multi-dimensional functions.
 
void ParameterGradient (const double *x, double *grad) const
 Evaluate all derivatives using cached parameter values (multi-dim like interface)
 
virtual void ParameterGradient (double x, const double *p, double *grad) const
 Evaluate the derivatives of the function with respect to the parameters at a point x.
 
void ParameterGradient (double x, double *grad) const
 Evaluate all derivatives using cached parameter values.
 
- Public Member Functions inherited from ROOT::Math::IParametricFunctionOneDim
double operator() (const double *x, const double *p) const
 multidim-like interface
 
double operator() (double x, const double *p) const
 Evaluate function at a point x and for given parameters p.
 
- Public Member Functions inherited from ROOT::Math::IBaseFunctionOneDim
virtual ~IBaseFunctionOneDim ()=default
 
double operator() (const double *x) const
 Evaluate the function at a point x[].
 
double operator() (double x) const
 Evaluate the function at a point x.
 
- Public Member Functions inherited from ROOT::Math::IBaseParam
virtual ~IBaseParam ()
 Virtual Destructor (no operations)
 
virtual std::string ParameterName (unsigned int i) const
 Return the name of the i-th parameter (starting from zero) Overwrite if want to avoid the default name ("Par_0, Par_1, ...")
 
- Public Member Functions inherited from ROOT::Math::IGradientFunctionOneDim
double Derivative (const double *x) const
 Compatibility method with multi-dimensional interface for partial derivative.
 
double Derivative (double x) const
 Return the derivative of the function at a point x Use the private method DoDerivative.
 
void FdF (const double *x, double &f, double *df) const
 Compatibility method with multi-dimensional interface for Gradient and function evaluation.
 
void Gradient (const double *x, double *g) const
 Compatibility method with multi-dimensional interface for Gradient.
 
bool HasGradient () const override
 

Private Member Functions

double DoDerivative (double x) const override
 Function to evaluate the derivative with respect each coordinate. To be implemented by the derived class.
 
double DoEvalPar (double x, const double *p) const override
 Implementation of the evaluation function using the x value and the parameters.
 
double DoParameterDerivative (double x, const double *p, unsigned int ipar) const override
 Evaluate the gradient, to be implemented by the derived classes.
 

Private Attributes

std::vector< doublefDerived_params
 
unsigned int fOrder
 
std::vector< std::complex< double > > fRoots
 

Additional Inherited Members

- Protected Attributes inherited from ROOT::Math::ParamFunction< IParamGradFunction >
std::vector< doublefParams
 

#include <Math/Polynomial.h>

Inheritance diagram for ROOT::Math::Polynomial:
[legend]

Member Typedef Documentation

◆ ParFunc

Constructor & Destructor Documentation

◆ Polynomial() [1/5]

ROOT::Math::Polynomial::Polynomial ( unsigned int  n = 0)

Construct a Polynomial function of order n.

The number of Parameters is n+1.

Definition at line 49 of file Polynomial.cxx.

◆ Polynomial() [2/5]

ROOT::Math::Polynomial::Polynomial ( double  a,
double  b 
)

Construct a Polynomial of degree 1 : a*x + b.

Definition at line 58 of file Polynomial.cxx.

◆ Polynomial() [3/5]

ROOT::Math::Polynomial::Polynomial ( double  a,
double  b,
double  c 
)

Construct a Polynomial of degree 2 : a*x**2 + b*x + c.

Definition at line 68 of file Polynomial.cxx.

◆ Polynomial() [4/5]

ROOT::Math::Polynomial::Polynomial ( double  a,
double  b,
double  c,
double  d 
)

Construct a Polynomial of degree 3 : a*x**3 + b*x**2 + c*x + d.

Definition at line 79 of file Polynomial.cxx.

◆ Polynomial() [5/5]

ROOT::Math::Polynomial::Polynomial ( double  a,
double  b,
double  c,
double  d,
double  e 
)

Construct a Polynomial of degree 4 : a*x**4 + b*x**3 + c*x**2 + dx + e.

Definition at line 92 of file Polynomial.cxx.

◆ ~Polynomial()

ROOT::Math::Polynomial::~Polynomial ( )
inlineoverride

Definition at line 100 of file Polynomial.h.

Member Function Documentation

◆ Clone()

IGenFunction * ROOT::Math::Polynomial::Clone ( ) const
overridevirtual

Clone a function.

Each derived class will implement their version of the private DoClone method.

Implements ROOT::Math::IBaseFunctionOneDim.

Definition at line 143 of file Polynomial.cxx.

◆ DoDerivative()

double ROOT::Math::Polynomial::DoDerivative ( double  x) const
overrideprivatevirtual

Function to evaluate the derivative with respect each coordinate. To be implemented by the derived class.

Implements ROOT::Math::IGradientFunctionOneDim.

Definition at line 127 of file Polynomial.cxx.

◆ DoEvalPar()

double ROOT::Math::Polynomial::DoEvalPar ( double  x,
const double p 
) const
overrideprivatevirtual

Implementation of the evaluation function using the x value and the parameters.

Must be implemented by derived classes

Implements ROOT::Math::IParametricFunctionOneDim.

Definition at line 119 of file Polynomial.cxx.

◆ DoParameterDerivative()

double ROOT::Math::Polynomial::DoParameterDerivative ( double  x,
const double p,
unsigned int  ipar 
) const
overrideprivatevirtual

Evaluate the gradient, to be implemented by the derived classes.

Implements ROOT::Math::IParametricGradFunctionOneDim.

Definition at line 136 of file Polynomial.cxx.

◆ FdF()

void ROOT::Math::Polynomial::FdF ( double  x,
double f,
double df 
) const
inlineoverridevirtual

Optimized method to evaluate at the same time the function value and derivative at a point x.

Implement the interface specified by ROOT::Math::IGradientOneDim. In the case of polynomial there is no advantage to compute both at the same time

Reimplemented from ROOT::Math::IGradientFunctionOneDim.

Definition at line 147 of file Polynomial.h.

◆ FindNumRoots()

const std::vector< std::complex< double > > & ROOT::Math::Polynomial::FindNumRoots ( )

Find the polynomial roots using always an iterative numerical methods The numerical method used is from GSL (see documentation )

Definition at line 247 of file Polynomial.cxx.

◆ FindRealRoots()

std::vector< double > ROOT::Math::Polynomial::FindRealRoots ( )

Find the only the real polynomial roots.

For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used The numerical method used is from GSL (see documentation )

Definition at line 237 of file Polynomial.cxx.

◆ FindRoots()

const std::vector< std::complex< double > > & ROOT::Math::Polynomial::FindRoots ( )

Find the polynomial roots.

For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used The numerical method used is from GSL (see documentation ) For the case of n = 4 by default an analytical algorithm is used from an implementation by Andrew W. Steiner and Andy Buckley which is a translation from the original Cenrlib routine (< HREF="https://cds.cern.ch/record/2050876/files/c208.html">RRTEQ4 ). Note that depending on the coefficients the result could be not very accurate if the discriminant of the resolvent cubic equation is very small. In that case it might be more robust to use the numerical method, by calling directly FindNumRoots()

Definition at line 151 of file Polynomial.cxx.

◆ Order()

unsigned int ROOT::Math::Polynomial::Order ( ) const
inline

Order of Polynomial.

Definition at line 137 of file Polynomial.h.

Member Data Documentation

◆ fDerived_params

std::vector<double> ROOT::Math::Polynomial::fDerived_params
mutableprivate

Definition at line 166 of file Polynomial.h.

◆ fOrder

unsigned int ROOT::Math::Polynomial::fOrder
private

Definition at line 163 of file Polynomial.h.

◆ fRoots

std::vector< std::complex < double > > ROOT::Math::Polynomial::fRoots
private

Definition at line 170 of file Polynomial.h.

Libraries for ROOT::Math::Polynomial:

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