casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
OddPolynomialParam.h
Go to the documentation of this file.
00001 //# OddPolynomialParam.h: Parameter handling for odd  polynomials
00002 //# Copyright (C) 2002,2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: OddPolynomialParam.h 21024 2011-03-01 11:46:18Z gervandiepen $
00027 
00028 #ifndef SCIMATH_ODDPOLYNOMIALPARAM_H
00029 #define SCIMATH_ODDPOLYNOMIALPARAM_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/Function1D.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/Utilities/Assert.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward declarations
00040 template<class T> class Vector;
00041 
00042 // <summary>  Parameter handling for odd polynomials
00043 // </summary>
00044 
00045 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tSpecialPolynomial"
00046 // demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class="FunctionParam">FunctionParam</linkto> class
00051 //   <li> <linkto class=Function1D>Function1D</linkto>
00052 // </prerequisite>
00053 
00054 // <etymology> 
00055 // A 1-dimensional OddPolynomial's parameters.
00056 // </etymology>
00057 //
00058 // <synopsis> 
00059 // An <src>OddPolynomial</src> is described by a set of coefficients;
00060 // its fundamental operation is evaluating itself at some "x".
00061 // The number of coefficients is the order of the polynomial divided
00062 // by two, plus one.
00063 //
00064 // Since the <src>OddPolynomial</src> is a <src>Function</src>, the derivatives
00065 // can be obtained as well. 
00066 //
00067 // The parameter interface (see 
00068 // <linkto class="FunctionParam">FunctionParam</linkto> class), 
00069 // is used to provide an interface to the
00070 // <linkto module="Fitting">Fitting</linkto> classes. 
00071 //
00072 // This class is in general used implicitly by the <src>OddPolynomial</src>
00073 // class only.
00074 // </synopsis> 
00075 //
00076 // <example>
00077 // <srcblock>
00078 //  OddPolynomial<Float> pf(3);  // Third order polynomial - coeffs 0 by default
00079 //  pf.setCoefficient(0, 1.0);
00080 //  pf[1] = 2.0;                // 2x^3 + 1x^1
00081 //  pf(2); // == 18
00082 // </srcblock>
00083 // </example>
00084 
00085 // <templating arg=T>
00086 //  <li> T should have standard numerical operators. Current
00087 //      implementation only tested for real types (and their AutoDiffs).
00088 // </templating>
00089 
00090 // <thrown>
00091 //    <li> Assertion in debug mode if attempt is made to address incorrect
00092 //              coefficients
00093 // </thrown>
00094 
00095 // <todo asof="2002/02/26">
00096 //   <li> Nothing I know off
00097 // </todo>
00098 
00099 template<class T> class OddPolynomialParam: public Function1D<T>
00100 {
00101 public:
00102   //# Constructors
00103   // Constructs a first order polynomial, with a coeficcient of 0.0.
00104   OddPolynomialParam();
00105   
00106   // Makes a polynomial of the given order, with all coeficcients set to
00107   // zero. 
00108   explicit OddPolynomialParam(uInt order);
00109   
00110   // Make this a copy of other (deep copy).
00111   // <group>
00112   OddPolynomialParam(const OddPolynomialParam<T> &other);
00113   template <class W>
00114     OddPolynomialParam(const OddPolynomialParam<W> &other) :
00115     Function1D<T>(other) {}
00116   OddPolynomialParam<T> &operator=(const OddPolynomialParam<T> &other);
00117   // </group>
00118   
00119   // Destructor
00120   ~OddPolynomialParam();
00121 
00122   //# Operators  
00123   // Comparisons.  
00124   // OddPolynomials are equal if they are the same order
00125   // <group>
00126   Bool operator==(const OddPolynomialParam<T> &other) const {
00127     return (param_p == other.param_p); }
00128   Bool operator!=(const OddPolynomialParam<T> &other) const {
00129     return (param_p != other.param_p); }
00130   // </group>
00131 
00132   //# Member functions
00133   // Give name of function
00134   virtual const String &name() const { static String x("oddpolynomial");
00135     return x; }
00136 
00137   // What is the order of the polynomial, i.e. maximum exponent of "x".
00138   uInt order() const { return 2*param_p.nelements() - 1; }
00139   
00140   // What is the <em>which</em>'th coefficient of the polynomial. For an nth
00141   // degree polynomial, <em>which</em> varies between zero and n/2.
00142   T coefficient(uInt which) const {
00143     DebugAssert(which<=order(), AipsError); return param_p[which]; }
00144   
00145   // Return all the coefficients as a vector.
00146   const Vector<T> &coefficients() const;
00147 
00148   // Set the <em>which</em>'th coefficient to <em>value</em>. 
00149   void setCoefficient(uInt which, const T value) {
00150     DebugAssert(which<=order(), AipsError); param_p[which] = value; }
00151   
00152   // Set all the coefficients at once, throw away all existing coefficients.
00153   void setCoefficients(const Vector<T> &coefficients);
00154 
00155   //# Make members of parent classes known.
00156 protected:
00157   using Function1D<T>::param_p;
00158 public:
00159   using Function1D<T>::nparameters;
00160 };
00161 
00162 
00163 } //# NAMESPACE CASA - END
00164 
00165 #ifndef CASACORE_NO_AUTO_TEMPLATES
00166 #include <scimath/Functionals/OddPolynomialParam.tcc>
00167 #endif //# CASACORE_NO_AUTO_TEMPLATES
00168 #endif