Logo ROOT   6.12/07
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 
36 #include "Math/ParamFunction.h"
37 
38 // #ifdef _WIN32
39 // #pragma warning(disable : 4250)
40 // #endif
41 
42 namespace ROOT {
43 namespace Math {
44 
45 //_____________________________________________________________________________________
46  /**
47  Parametric Function class describing polynomials of order n.
48 
49  <em>P(x) = p[0] + p[1]*x + p[2]*x**2 + ....... + p[n]*x**n</em>
50 
51  The class implements also the derivatives, \a dP(x)/dx and the \a dP(x)/dp[i].
52 
53  The class provides also the method to find the roots of the polynomial.
54  It uses analytical methods up to quartic polynomials.
55 
56  Implements both the Parameteric function interface and the gradient interface
57  since it provides the analytical gradient with respect to x
58 
59 
60  @ingroup ParamFunc
61  */
62 
63 class Polynomial : public ParamFunction<IParamGradFunction>,
64  public IGradientOneDim
65 {
66 
67 
68 public:
69 
71  /**
72  Construct a Polynomial function of order n.
73  The number of Parameters is n+1.
74  */
75 
76  Polynomial(unsigned int n = 0);
77 
78  /**
79  Construct a Polynomial of degree 1 : a*x + b
80  */
81  Polynomial(double a, double b);
82 
83  /**
84  Construct a Polynomial of degree 2 : a*x**2 + b*x + c
85  */
86  Polynomial(double a, double b, double c);
87 
88  /**
89  Construct a Polynomial of degree 3 : a*x**3 + b*x**2 + c*x + d
90  */
91  Polynomial(double a, double b, double c, double d);
92 
93  /**
94  Construct a Polynomial of degree 4 : a*x**4 + b*x**3 + c*x**2 + dx + e
95  */
96  Polynomial(double a, double b, double c, double d, double e);
97 
98 
99  virtual ~Polynomial() {}
100 
101  // use default copy-ctor and assignment operators
102 
103 
104 
105 // using ParamFunction::operator();
106 
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="http://www.gnu.org/software/gsl/manual/gsl-ref_6.html#SEC53" )
112  */
113  const std::vector<std::complex <double> > & FindRoots();
114 
115 
116  /**
117  Find the only the real polynomial roots.
118  For n <= 4, the roots are found analytically while for larger order an iterative numerical method is used
119  The numerical method used is from GSL (see <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_6.html#SEC53" )
120  */
121  std::vector<double > FindRealRoots();
122 
123 
124  /**
125  Find the polynomial roots using always an iterative numerical methods
126  The numerical method used is from GSL (see <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_6.html#SEC53" )
127  */
128  const std::vector<std::complex <double> > & FindNumRoots();
129 
130  /**
131  Order of Polynomial
132  */
133  unsigned int Order() const { return fOrder; }
134 
135 
136  IGenFunction * Clone() const;
137 
138  /**
139  Optimized method to evaluate at the same time the function value and derivative at a point x.
140  Implement the interface specified bby ROOT::Math::IGradientOneDim.
141  In the case of polynomial there is no advantage to compute both at the same time
142  */
143  void FdF (double x, double & f, double & df) const {
144  f = (*this)(x);
145  df = Derivative(x);
146  }
147 
148 
149 private:
150 
151  double DoEvalPar ( double x, const double * p ) const ;
152 
153  double DoDerivative (double x) const ;
154 
155  double DoParameterDerivative(double x, const double * p, unsigned int ipar) const;
156 
157 
158  // cache order = number of params - 1)
159  unsigned int fOrder;
160 
161  // cache Parameters for Gradient
162  mutable std::vector<double> fDerived_params;
163 
164  // roots
165 
166  std::vector< std::complex < double > > fRoots;
167 
168 };
169 
170 } // namespace Math
171 } // namespace ROOT
172 
173 
174 #endif /* ROOT_Math_Polynomial */
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Polynomial(unsigned int n=0)
Construct a Polynomial function of order n.
Definition: Polynomial.cxx:50
std::vector< double > FindRealRoots()
Find the only the real polynomial roots.
Definition: Polynomial.cxx:238
std::vector< double > fDerived_params
Definition: Polynomial.h:162
const std::vector< std::complex< double > > & FindRoots()
Find the polynomial roots.
Definition: Polynomial.cxx:152
ParamFunction< IParamGradFunction > ParFunc
Definition: Polynomial.h:70
Specialized Gradient interface(abstract class) for one dimensional functions It provides a method to ...
Definition: IFunction.h:247
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:248
Double_t x[n]
Definition: legend1.C:17
unsigned int Order() const
Order of Polynomial.
Definition: Polynomial.h:133
double DoEvalPar(double x, const double *p) const
Implementation of the evaluation function using the x value and the parameters.
Definition: Polynomial.cxx:120
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:143
IGenFunction * Clone() const
Clone a function.
Definition: Polynomial.cxx:144
unsigned int fOrder
Definition: Polynomial.h:159
std::vector< std::complex< double > > fRoots
Definition: Polynomial.h:166
auto * a
Definition: textangle.C:12
Base template class for all Parametric Functions.
Definition: ParamFunction.h:67
Parametric Function class describing polynomials of order n.
Definition: Polynomial.h:63
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Namespace for new Math classes and functions.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
double Derivative(double x) const
Return the derivative of the function at a point x Use the private method DoDerivative.
Definition: IFunction.h:258
double DoParameterDerivative(double x, const double *p, unsigned int ipar) const
Evaluate the gradient, to be implemented by the derived classes.
Definition: Polynomial.cxx:137
double DoDerivative(double x) const
function to evaluate the derivative with respect each coordinate.
Definition: Polynomial.cxx:128
const Int_t n
Definition: legend1.C:16