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