casa
$Rev:20696$
|
00001 //# PolynomialParam.h: Parameter handling for one-dimensional polynomials 00002 //# Copyright (C) 2001,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: PolynomialParam.h 21024 2011-03-01 11:46:18Z gervandiepen $ 00027 00028 #ifndef SCIMATH_POLYNOMIALPARAM_H 00029 #define SCIMATH_POLYNOMIALPARAM_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <casa/BasicSL/String.h> 00034 #include <casa/Utilities/Assert.h> 00035 #include <scimath/Functionals/Function1D.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 //# Forward declarations 00040 template<class T> class Vector; 00041 00042 // <summary> Parameter handling for one-dimensional polynomials 00043 // </summary> 00044 00045 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tPolynomial" 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 Polynomial's parameters. 00056 // </etymology> 00057 // 00058 // <synopsis> 00059 // A <src>Polynomial</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 plus one. 00062 // 00063 // Since the <src>Polynomial</src> is a <src>Function</src>, the derivatives 00064 // 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>Polynomial</src> 00072 // class only. 00073 // </synopsis> 00074 // 00075 // <example> 00076 // <srcblock> 00077 // Polynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default 00078 // pf.setCoefficient(1, 1.0); 00079 // pf[2] = 2.0; 00080 // pf.setCoefficient(3, 3.0); // 3x^3 + 2x^2 + x 00081 // pf(2); // == 34 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="1995/08/25"> 00096 // <li> Global functions to make various ``special'' polynomials of various 00097 // orders will be useful eventually. 00098 // </todo> 00099 00100 template<class T> class PolynomialParam: public Function1D<T> { 00101 public: 00102 //# Constructors 00103 // Constructs a zero'th order polynomial, with a coeficcient of 0.0. 00104 PolynomialParam(); 00105 00106 // Makes a polynomial of the given order, with all coeficcients set to 00107 // zero. 00108 explicit PolynomialParam(uInt order); 00109 00110 // Make this a copy of other (deep copy). 00111 // <group> 00112 PolynomialParam(const PolynomialParam<T> &other); 00113 template <class W> 00114 PolynomialParam(const PolynomialParam<W> &other) : 00115 Function1D<T>(other) {} 00116 PolynomialParam<T> &operator=(const PolynomialParam<T> &other); 00117 // </group> 00118 00119 // Destructor 00120 ~PolynomialParam(); 00121 00122 //# Operators 00123 // Comparisons. 00124 // Polynomials are equal if they are the same order 00125 // <group> 00126 Bool operator==(const PolynomialParam<T> &other) const { 00127 return (param_p == other.param_p); } 00128 Bool operator!=(const PolynomialParam<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("polynomial"); 00135 return x; } 00136 00137 // What is the order of the polynomial, i.e. maximum exponent of "x". 00138 uInt order() const { return 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. 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/PolynomialParam.tcc> 00167 #endif //# CASACORE_NO_AUTO_TEMPLATES 00168 #endif