casa
$Rev:20696$
|
00001 //# EvenPolynomialParam.h: Parameter handling for even 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: EvenPolynomialParam.h 21024 2011-03-01 11:46:18Z gervandiepen $ 00027 00028 #ifndef SCIMATH_EVENPOLYNOMIALPARAM_H 00029 #define SCIMATH_EVENPOLYNOMIALPARAM_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <scimath/Functionals/Function1D.h> 00034 #include <casa/Utilities/Assert.h> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 //# Forward declarations 00039 template<class T> class Vector; 00040 00041 // <summary> Parameter handling for even polynomials 00042 // </summary> 00043 00044 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tSpecialPolynomial" 00045 // demos=""> 00046 // </reviewed> 00047 00048 // <prerequisite> 00049 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class 00050 // <li> <linkto class=Function1D>Function1D</linkto> 00051 // </prerequisite> 00052 00053 // <etymology> 00054 // A 1-dimensional EvenPolynomial's parameters. 00055 // </etymology> 00056 // 00057 // <synopsis> 00058 // An <src>EvenPolynomial</src> is described by a set of coefficients; 00059 // its fundamental operation is evaluating itself at some "x". 00060 // The number of coefficients is the order of the polynomial divided 00061 // by two, plus one. 00062 // 00063 // Since the <src>EvenPolynomial</src> is a <src>Function</src>, 00064 // the derivatives can be obtained as well. 00065 // 00066 // The parameter interface (see 00067 // <linkto class="FunctionParam">FunctionParam</linkto> class), 00068 // is used to provide an interface to the 00069 // <linkto module="Fitting">Fitting</linkto> classes. 00070 // 00071 // This class is in general used implicitly by the <src>EvenPolynomial</src> 00072 // class only. 00073 // </synopsis> 00074 // 00075 // <example> 00076 // <srcblock> 00077 // EvenPolynomial<Float> pf(3); // Second order polynomial - coeffs 0 by default 00078 // pf.setCoefficient(0, 1.0); 00079 // pf[1] = 2.0; // 2x^2 + 1x^0 00080 // pf(2); // == 8 00081 // </srcblock> 00082 // </example> 00083 00084 // <templating arg=T> 00085 // <li> T should have standard numerical operators. Current 00086 // implementation only tested for real types (and their AutoDiffs). 00087 // </templating> 00088 00089 // <thrown> 00090 // <li> Assertion in debug mode if attempt is made to address incorrect 00091 // coefficients 00092 // </thrown> 00093 00094 // <todo asof="2002/02/26"> 00095 // <li> Nothing I know of 00096 // </todo> 00097 00098 template<class T> class EvenPolynomialParam: public Function1D<T> 00099 { 00100 public: 00101 //# Constructors 00102 // Constructs a zero'th order polynomial, with a coeficcient of 0.0. 00103 EvenPolynomialParam(); 00104 00105 // Makes a polynomial of the given order, with all coeficcients set to 00106 // zero. 00107 explicit EvenPolynomialParam(uInt order); 00108 00109 // Make this a copy of other (deep copy). 00110 // <group> 00111 EvenPolynomialParam(const EvenPolynomialParam<T> &other); 00112 template <class W> 00113 EvenPolynomialParam(const EvenPolynomialParam<W> &other) : 00114 Function1D<T>(other) {} 00115 EvenPolynomialParam<T> &operator=(const EvenPolynomialParam<T> &other); 00116 // </group> 00117 00118 // Destructor 00119 ~EvenPolynomialParam(); 00120 00121 //# Operators 00122 // Comparisons. 00123 // EvenPolynomials are equal if they are the same order 00124 // <group> 00125 Bool operator==(const EvenPolynomialParam<T> &other) const { 00126 return (param_p == other.param_p); } 00127 Bool operator!=(const EvenPolynomialParam<T> &other) const { 00128 return (param_p != other.param_p); } 00129 // </group> 00130 00131 //# Member functions 00132 // Give name of function 00133 virtual const String &name() const { static String x("evenpolynomial"); 00134 return x; } 00135 00136 // What is the order of the polynomial, i.e. maximum exponent of "x". 00137 uInt order() const { return 2*param_p.nelements() - 2; } 00138 00139 // What is the <em>which</em>'th coefficient of the polynomial. For an nth 00140 // degree polynomial, <em>which</em> varies between zero and n/2. 00141 T coefficient(uInt which) const { 00142 DebugAssert(which<=order(), AipsError); return param_p[which]; } 00143 00144 // Return all the coefficients as a vector. 00145 const Vector<T> &coefficients() const; 00146 00147 // Set the <em>which</em>'th coefficient to <em>value</em>. 00148 void setCoefficient(uInt which, const T value) { 00149 DebugAssert(which<=order(), AipsError); param_p[which] = value; } 00150 00151 // Set all the coefficients at once, throw away all existing coefficients. 00152 void setCoefficients(const Vector<T> &coefficients); 00153 00154 //# Make members of parent classes known. 00155 protected: 00156 using Function1D<T>::param_p; 00157 public: 00158 using Function1D<T>::nparameters; 00159 }; 00160 00161 00162 } //# NAMESPACE CASA - END 00163 00164 #ifndef CASACORE_NO_AUTO_TEMPLATES 00165 #include <scimath/Functionals/EvenPolynomialParam.tcc> 00166 #endif //# CASACORE_NO_AUTO_TEMPLATES 00167 #endif