Logo ROOT  
Reference Guide
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>,
65 public IGradientOneDim
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 virtual ~Polynomial() {}
101
102 // use default copy-ctor and assignment operators
103
104
105
106// using ParamFunction::operator();
107
108
109 /**
110 Find the polynomial roots.
111 For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used
112 The numerical method used is from GSL (see <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_6.html#SEC53" )
113 */
114 const std::vector<std::complex <double> > & FindRoots();
115
116
117 /**
118 Find the only the real polynomial roots.
119 For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used
120 The numerical method used is from GSL (see <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_6.html#SEC53" )
121 */
122 std::vector<double > FindRealRoots();
123
124
125 /**
126 Find the polynomial roots using always an iterative numerical methods
127 The numerical method used is from GSL (see <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_6.html#SEC53" )
128 */
129 const std::vector<std::complex <double> > & FindNumRoots();
130
131 /**
132 Order of Polynomial
133 */
134 unsigned int Order() const { return fOrder; }
135
136
137 IGenFunction * Clone() const;
138
139 /**
140 Optimized method to evaluate at the same time the function value and derivative at a point x.
141 Implement the interface specified bby ROOT::Math::IGradientOneDim.
142 In the case of polynomial there is no advantage to compute both at the same time
143 */
144 void FdF (double x, double & f, double & df) const {
145 f = (*this)(x);
146 df = Derivative(x);
147 }
148
149
150private:
151
152 double DoEvalPar ( double x, const double * p ) const ;
153
154 double DoDerivative (double x) const ;
155
156 double DoParameterDerivative(double x, const double * p, unsigned int ipar) const;
157
158
159 // cache order = number of params - 1)
160 unsigned int fOrder;
161
162 // cache Parameters for Gradient
163 mutable std::vector<double> fDerived_params;
164
165 // roots
166
167 std::vector< std::complex < double > > fRoots;
168
169};
170
171} // namespace Math
172} // namespace ROOT
173
174
175#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 e(i)
Definition: RSha256.hxx:103
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Specialized Gradient interface(abstract class) for one dimensional functions It provides a method to ...
Definition: IFunction.h:263
double Derivative(double x) const
Return the derivative of the function at a point x Use the private method DoDerivative.
Definition: IFunction.h:274
Base template class for all Parametric Functions.
Definition: ParamFunction.h:67
Parametric Function class describing polynomials of order n.
Definition: Polynomial.h:66
IGenFunction * Clone() const
Clone a function.
Definition: Polynomial.cxx:143
void FdF(double x, double &f, double &df) const
Optimized method to evaluate at the same time the function value and derivative at a point x.
Definition: Polynomial.h:144
double DoDerivative(double x) const
function to evaluate the derivative with respect each coordinate.
Definition: Polynomial.cxx:127
const std::vector< std::complex< double > > & FindRoots()
Find the polynomial roots.
Definition: Polynomial.cxx:151
std::vector< std::complex< double > > fRoots
Definition: Polynomial.h:167
Polynomial(unsigned int n=0)
Construct a Polynomial function of order n.
Definition: Polynomial.cxx:49
unsigned int fOrder
Definition: Polynomial.h:160
ParamFunction< IParamGradFunction > ParFunc
Definition: Polynomial.h:71
unsigned int Order() const
Order of Polynomial.
Definition: Polynomial.h:134
double DoParameterDerivative(double x, const double *p, unsigned int ipar) const
Evaluate the gradient, to be implemented by the derived classes.
Definition: Polynomial.cxx:136
double DoEvalPar(double x, const double *p) const
Implementation of the evaluation function using the x value and the parameters.
Definition: Polynomial.cxx:119
std::vector< double > FindRealRoots()
Find the only the real polynomial roots.
Definition: Polynomial.cxx:237
const std::vector< std::complex< double > > & FindNumRoots()
Find the polynomial roots using always an iterative numerical methods The numerical method used is fr...
Definition: Polynomial.cxx:247
std::vector< double > fDerived_params
Definition: Polynomial.h:163
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...
auto * a
Definition: textangle.C:12