casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PolynomialParam.h
Go to the documentation of this file.
1 //# PolynomialParam.h: Parameter handling for one-dimensional polynomials
2 //# Copyright (C) 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_POLYNOMIALPARAM_H
29 #define SCIMATH_POLYNOMIALPARAM_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 // <summary> Parameter handling for one-dimensional polynomials
41 // </summary>
42 
43 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tPolynomial"
44 // demos="">
45 // </reviewed>
46 
47 // <prerequisite>
48 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class
49 // <li> <linkto class=Function1D>Function1D</linkto>
50 // </prerequisite>
51 
52 // <etymology>
53 // A 1-dimensional Polynomial's parameters.
54 // </etymology>
55 //
56 // <synopsis>
57 // A <src>Polynomial</src> is described by a set of coefficients;
58 // its fundamental operation is evaluating itself at some "x".
59 // The number of coefficients is the order of the polynomial plus one.
60 //
61 // Since the <src>Polynomial</src> is a <src>Function</src>, the derivatives
62 // can be obtained as well.
63 //
64 // The parameter interface (see
65 // <linkto class="FunctionParam">FunctionParam</linkto> class),
66 // is used to provide an interface to the
67 // <linkto module="Fitting">Fitting</linkto> classes.
68 //
69 // This class is in general used implicitly by the <src>Polynomial</src>
70 // class only.
71 // </synopsis>
72 //
73 // <example>
74 // <srcblock>
75 // Polynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default
76 // pf.setCoefficient(1, 1.0);
77 // pf[2] = 2.0;
78 // pf.setCoefficient(3, 3.0); // 3x^3 + 2x^2 + x
79 // pf(2); // == 34
80 // </srcblock>
81 // </example>
82 
83 // <templating arg=T>
84 // <li> T should have standard numerical operators. Current
85 // implementation only tested for real types (and their AutoDiffs).
86 // </templating>
87 
88 // <thrown>
89 // <li> Assertion in debug mode if attempt is made to address incorrect
90 // coefficients
91 // </thrown>
92 
93 // <todo asof="1995/08/25">
94 // <li> Global functions to make various ``special'' polynomials of various
95 // orders will be useful eventually.
96 // </todo>
97 
98 template<class T> class PolynomialParam: public Function1D<T> {
99 public:
100  //# Constructors
101  // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
102  PolynomialParam();
103 
104  // Makes a polynomial of the given order, with all coeficcients set to
105  // zero.
106  explicit PolynomialParam(uInt order);
107 
108  // Make this a copy of other (deep copy).
109  // <group>
110  PolynomialParam(const PolynomialParam<T> &other);
111  template <class W>
113  Function1D<T>(other) {}
115  // </group>
116 
117  // Destructor
119 
120  //# Operators
121  // Comparisons.
122  // Polynomials are equal if they are the same order
123  // <group>
124  Bool operator==(const PolynomialParam<T> &other) const {
125  return (param_p == other.param_p); }
126  Bool operator!=(const PolynomialParam<T> &other) const {
127  return (param_p != other.param_p); }
128  // </group>
129 
130  //# Member functions
131  // Give name of function
132  virtual const String &name() const { static String x("polynomial");
133  return x; }
134 
135  // What is the order of the polynomial, i.e. maximum exponent of "x".
136  uInt order() const { return param_p.nelements() - 1; }
137 
138  // What is the <em>which</em>'th coefficient of the polynomial. For an nth
139  // degree polynomial, <em>which</em> varies between zero and n.
140  T coefficient(uInt which) const {
141  DebugAssert(which<=order(), AipsError); return param_p[which]; }
142 
143  // Return all the coefficients as a vector.
144  const Vector<T> &coefficients() const;
145 
146  // Set the <em>which</em>'th coefficient to <em>value</em>.
147  void setCoefficient(uInt which, const T value) {
148  DebugAssert(which<=order(), AipsError); param_p[which] = value; }
149 
150  // Set all the coefficients at once, throw away all existing coefficients.
152 
153  //# Make members of parent classes known.
154 protected:
156 public:
158 };
159 
160 
161 } //# NAMESPACE CASACORE - END
162 
163 #ifndef CASACORE_NO_AUTO_TEMPLATES
164 #include <casacore/scimath/Functionals/PolynomialParam.tcc>
165 #endif //# CASACORE_NO_AUTO_TEMPLATES
166 #endif
PolynomialParam< T > & operator=(const PolynomialParam< T > &other)
T coefficient(uInt which) const
What is the which&#39;th coefficient of the polynomial.
virtual const String & name() const
Give name of function.
FunctionParam< T > param_p
The parameters and masks.
Definition: Function.h:332
PolynomialParam()
Constructs a zero&#39;th order polynomial, with a coeficcient of 0.0.
PolynomialParam(const PolynomialParam< W > &other)
Parameter handling for one-dimensional polynomials.
~PolynomialParam()
Destructor.
Bool operator!=(const PolynomialParam< T > &other) const
void setCoefficient(uInt which, const T value)
Set the which&#39;th coefficient to value.
const Vector< T > & coefficients() const
Return all the coefficients as a vector.
#define DebugAssert(expr, exception)
Definition: Assert.h:185
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool operator==(const PolynomialParam< T > &other) const
Comparisons.
Numerical functional interface class for 1 dimension.
Definition: Function1D.h:75
Base class for all Casacore library errors.
Definition: Error.h:134
String: the storage and methods of handling collections of characters.
Definition: String.h:225
uInt order() const
What is the order of the polynomial, i.e.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
void setCoefficients(const Vector< T > &coefficients)
Set all the coefficients at once, throw away all existing coefficients.