casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Polynomial.h
Go to the documentation of this file.
1 //# Polynomial.h: A one dimensional polynomial class
2 //# Copyright (C) 1994,1995,1996,2001,2002,2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef SCIMATH_POLYNOMIAL_H
29 #define SCIMATH_POLYNOMIAL_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward declarations
41 
42 // <summary> A one dimensional polynomial class
43 // </summary>
44 
45 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tPolynomial"
46 // demos="">
47 // </reviewed>
48 
49 // <prerequisite>
50 // <li> <linkto class=Function>Function</linkto>
51 // </prerequisite>
52 //
53 // <synopsis>
54 // A Polynomial<T> contains a set of coefficients; its fundamental operations
55 // is evaluating itself at some "x". The number of coefficients is the order
56 // of the polynomial plus one, so is the number of available parameters.
57 //
58 // <note role=tip>
59 // The present implementation merely stores the coefficients in a Block. In the
60 // unlikely case that we need to deal with polynomials with many zero
61 // coefficients, a more efficient representation would be possible.
62 // </note>
63 // </synopsis>
64 //
65 // <example>
66 // <srcblock>
67 // Polynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default
68 // pf.setCoefficient(1, 1.0);
69 // pf[2] = 2.0;
70 // pf.setCoefficient(3, 3.0); // 3x^3 + 2x^2 + x
71 // pf(2); // == 34
72 // </srcblock>
73 // </example>
74 
75 // <templating arg=T>
76 // <li> T should have standard numerical operators. Current
77 // implementation only tested for real types (and their AutoDiffs).
78 // </templating>
79 
80 // <thrown>
81 // <li> Assertion in debug mode if attempt is made to address incorrect
82 // coefficients
83 // </thrown>
84 
85 // <todo asof="1995/08/25">
86 // <li> Global functions to make various ``special'' polynomials of various
87 // orders will be useful eventually.
88 // </todo>
89 
90 template<class T> class Polynomial: public PolynomialParam<T> {
91 public:
92  //# Enumerations
93 
94  //# Constructors
95  // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
97  // Makes a polynomial of the given order, with all coeficcients set to
98  // zero.
99  explicit Polynomial(uInt order) : PolynomialParam<T>(order) {}
100  // Copy constructor/assignment (deep copy)
101  // <group>
102  Polynomial(const Polynomial<T> &other) : PolynomialParam<T>(other) {}
103  template <class W>
104  Polynomial(const Polynomial<W> &other) : PolynomialParam<T>(other) {}
106  PolynomialParam<T>::operator=(other); return *this; }
107  // </group>
108 
109  // Destructor
110  virtual ~Polynomial() {}
111 
112  //# Operators
113  // Evaluate the polynomial at <src>x</src>.
114  virtual T eval(typename Function1D<T>::FunctionArg x) const;
115 
116  //# Member functions
117  // Return the polynomial which is the derivative of this one. <em>e.g.,</em>
118  // <src> 2+4x+5x^2 --> 0+4+10x </src>.
119  Polynomial<T> derivative() const;
120 
121  // Return a copy of this object from the heap. The caller is responsible for
122  // deleting the pointer.
123  // <group>
124  virtual Function<T> *clone() const { return new Polynomial<T>(*this); }
129  // </group>
130 
131  //# Make members of parent classes known.
132 protected:
134 public:
137 
138 };
139 
140 #define Polynomial_PS Polynomial
141 
142 // <summary> Partial specialization of Polynomial for <src>AutoDiff</src>
143 // </summary>
144 
145 // <synopsis>
146 // <note role=warning> The name <src>Polynomial_PS</src> is only for cxx2html
147 // documentation problems. Use <src>Polynomial</src> in your code.</note>
148 // </synopsis>
150 template <class T> class Polynomial_PS<AutoDiff<T> > :
151 public PolynomialParam<AutoDiff<T> > {
152 public:
153  //# Constructors
154  // Constructs one dimensional Polynomials.
155  // <group>
157  explicit Polynomial_PS(uInt order) :
158  PolynomialParam<AutoDiff<T> >(order) {}
159  // </group>
160 
161  // Copy constructor (deep copy)
162  // <group>
163  Polynomial_PS(const Polynomial_PS<AutoDiff<T> > &other) :
164  PolynomialParam<AutoDiff<T> >(other) {}
165  template <class W>
166  Polynomial_PS(const Polynomial_PS<W> &other) :
167  PolynomialParam<AutoDiff<T> >(other) {}
168  // </group>
169 
170  // Copy assignment (deep copy)
171  Polynomial_PS<AutoDiff<T> > &
172  operator=(const Polynomial_PS<AutoDiff<T> > &other) {
173  PolynomialParam<AutoDiff<T> >::operator=(other); return *this; }
174 
175  // Destructor
176  virtual ~Polynomial_PS() {}
177 
178  //# Operators
179  // Evaluate the polynomial and its derivatives at <src>x</src> <em>wrt</em>
180  // to the coefficients.
181  // <group>
182  virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
183  // </group>
184 
185  //# Member functions
186  // Return a copy of this object from the heap. The caller is responsible
187  // for deleting this pointer.
188  // <group>
189  virtual Function<AutoDiff<T> > *clone() const {
190  return new Polynomial<AutoDiff<T> >(*this); }
192  *cloneAD() const {
193  return new Polynomial<typename FunctionTraits<AutoDiff<T> >::DiffType>
194  (*this); }
196  *cloneNonAD() const {
197  return new Polynomial<typename FunctionTraits<AutoDiff<T> >::BaseType>
198  (*this); }
199  // </group>
200 
201  //# Make members of parent classes known.
202 protected:
203  using PolynomialParam<AutoDiff<T> >::param_p;
204 public:
205  using PolynomialParam<AutoDiff<T> >::nparameters;
206  using PolynomialParam<AutoDiff<T> >::order;
207 };
208 
209 #undef Polynomial_PS
210 
211 
212 } //# NAMESPACE CASACORE - END
213 
214 #ifndef CASACORE_NO_AUTO_TEMPLATES
215 #include <casacore/scimath/Functionals/Polynomial.tcc>
216 #include <casacore/scimath/Functionals/Polynomial2.tcc>
217 #endif //# CASACORE_NO_AUTO_TEMPLATES
218 #endif
PolynomialParam< T > & operator=(const PolynomialParam< T > &other)
Parameter handling for one-dimensional polynomials.
virtual T eval(typename Function1D< T >::FunctionArg x) const
Evaluate the polynomial at x.
Polynomial< T > & operator=(const Polynomial< T > &other)
Definition: Polynomial.h:105
virtual ~Polynomial()
Destructor.
Definition: Polynomial.h:110
PtrHolder< T > & operator=(const PtrHolder< T > &other)
Polynomial()
Constructs a zero&#39;th order polynomial, with a coeficcient of 0.0.
Definition: Polynomial.h:96
A one dimensional polynomial class.
Definition: Polynomial.h:90
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition: Polynomial.h:127
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition: Polynomial.h:125
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
Polynomial(const Polynomial< W > &other)
Definition: Polynomial.h:104
Numerical functional interface class for 1 dimension.
Definition: Function1D.h:75
Polynomial< T > derivative() const
Return the polynomial which is the derivative of this one.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition: Polynomial.h:124
Polynomial(uInt order)
Makes a polynomial of the given order, with all coeficcients set to zero.
Definition: Polynomial.h:99
uInt order() const
What is the order of the polynomial, i.e.
Polynomial(const Polynomial< T > &other)
Copy constructor/assignment (deep copy)
Definition: Polynomial.h:102
#define Polynomial_PS
Definition: Polynomial.h:140
unsigned int uInt
Definition: aipstype.h:51