Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Polynomial.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Authors: L. Moneta, A. Zsenei 08/2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library (see file COPYING); if not, write *
20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21 * 330, Boston, MA 02111-1307 USA, or contact the author. *
22 * *
23 **********************************************************************/
24
25// Header file for class Polynomial
26//
27// Created by: Lorenzo Moneta at Wed Nov 10 17:46:19 2004
28//
29// Last update: Wed Nov 10 17:46:19 2004
30//
31#ifndef ROOT_Math_Polynomial
32#define ROOT_Math_Polynomial
33
34#include <complex>
35#include <vector>
36
37#include "Math/ParamFunction.h"
38
39// #ifdef _WIN32
40// #pragma warning(disable : 4250)
41// #endif
42
43namespace ROOT {
44namespace Math {
45
46//_____________________________________________________________________________________
47 /**
48 Parametric Function class describing polynomials of order n.
49
50 <em>P(x) = p[0] + p[1]*x + p[2]*x**2 + ....... + p[n]*x**n</em>
51
52 The class implements also the derivatives, \a dP(x)/dx and the \a dP(x)/dp[i].
53
54 The class provides also the method to find the roots of the polynomial.
55 It uses analytical methods up to quartic polynomials.
56
57 Implements both the Parameteric function interface and the gradient interface
58 since it provides the analytical gradient with respect to x
59
60
61 @ingroup ParamFunc
62 */
63
64class Polynomial : public ParamFunction<IParamGradFunction>,
66{
67
68
69public:
70
72 /**
73 Construct a Polynomial function of order n.
74 The number of Parameters is n+1.
75 */
76
77 Polynomial(unsigned int n = 0);
78
79 /**
80 Construct a Polynomial of degree 1 : a*x + b
81 */
82 Polynomial(double a, double b);
83
84 /**
85 Construct a Polynomial of degree 2 : a*x**2 + b*x + c
86 */
87 Polynomial(double a, double b, double c);
88
89 /**
90 Construct a Polynomial of degree 3 : a*x**3 + b*x**2 + c*x + d
91 */
92 Polynomial(double a, double b, double c, double d);
93
94 /**
95 Construct a Polynomial of degree 4 : a*x**4 + b*x**3 + c*x**2 + dx + e
96 */
97 Polynomial(double a, double b, double c, double d, double e);
98
99
100 ~Polynomial() override {}
101
102 // use default copy-ctor and assignment operators
103
104
105
106// using ParamFunction::operator();
107
108 /**
109 Find the polynomial roots.
110 For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used
111 The numerical method used is from GSL (see <A HREF="https://www.gnu.org/software/gsl/doc/html/poly.html">documentation</A> )
112 For the case of n = 4 by default an analytical algorithm is used from an implementation by
113 Andrew W. Steiner and Andy Buckley which is a translation from the original Cenrlib routine
114 (< HREF="https://cds.cern.ch/record/2050876/files/c208.html">RRTEQ4</A> ).
115 Note that depending on the coefficients the result could be not very accurate if the discriminant of the resolvent cubic
116 equation is very small. In that case it might be more robust to use the numerical method, by calling directly FindNumRoots()
117
118 */
119 const std::vector<std::complex <double> > & FindRoots();
120
121 /**
122 Find the only the real polynomial roots.
123 For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used
124 The numerical method used is from GSL (see <A HREF="https://www.gnu.org/software/gsl/doc/html/poly.html">documentation</A> )
125 */
126 std::vector<double > FindRealRoots();
127
128 /**
129 Find the polynomial roots using always an iterative numerical methods
130 The numerical method used is from GSL (see <A HREF="https://www.gnu.org/software/gsl/doc/html/poly.html">documentation</A> )
131 */
132 const std::vector<std::complex <double> > & FindNumRoots();
133
134 /**
135 Order of Polynomial
136 */
137 unsigned int Order() const { return fOrder; }
138
139
140 IGenFunction * Clone() const override;
141
142 /**
143 Optimized method to evaluate at the same time the function value and derivative at a point x.
144 Implement the interface specified by ROOT::Math::IGradientOneDim.
145 In the case of polynomial there is no advantage to compute both at the same time
146 */
147 void FdF (double x, double & f, double & df) const override {
148 f = (*this)(x);
149 df = Derivative(x);
150 }
151
152
153private:
154
155 double DoEvalPar ( double x, const double * p ) const override ;
156
157 double DoDerivative (double x) const override ;
158
159 double DoParameterDerivative(double x, const double * p, unsigned int ipar) const override;
160
161
162 // cache order = number of params - 1)
163 unsigned int fOrder;
164
165 // cache Parameters for Gradient
166 mutable std::vector<double> fDerived_params;
167
168 // roots
169
170 std::vector< std::complex < double > > fRoots;
171
172};
173
174} // namespace Math
175} // namespace ROOT
176
177
178#endif /* ROOT_Math_Polynomial */
#define d(i)
Definition RSha256.hxx:102
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
winID h TVirtualViewer3D TVirtualGLPainter p
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:112
Interface (abstract class) for one-dimensional functions providing a gradient calculation.
Definition IFunction.h:254
double Derivative(double x) const
Return the derivative of the function at a point x Use the private method DoDerivative.
Definition IFunction.h:263
Base template class for all Parametric Functions.
Parametric Function class describing polynomials of order n.
Definition Polynomial.h:66
const std::vector< std::complex< double > > & FindRoots()
Find the polynomial roots.
std::vector< std::complex< double > > fRoots
Definition Polynomial.h:170
double DoEvalPar(double x, const double *p) const override
Implementation of the evaluation function using the x value and the parameters.
ParamFunction< IParamGradFunction > ParFunc
Definition Polynomial.h:71
unsigned int Order() const
Order of Polynomial.
Definition Polynomial.h:137
IGenFunction * Clone() const override
Clone a function.
double DoParameterDerivative(double x, const double *p, unsigned int ipar) const override
Evaluate the gradient, to be implemented by the derived classes.
std::vector< double > FindRealRoots()
Find the only the real polynomial roots.
const std::vector< std::complex< double > > & FindNumRoots()
Find the polynomial roots using always an iterative numerical methods The numerical method used is fr...
double DoDerivative(double x) const override
Function to evaluate the derivative with respect each coordinate. To be implemented by the derived cl...
std::vector< double > fDerived_params
Definition Polynomial.h:166
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.
Definition Polynomial.h:147
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...