casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SPolynomial.h
Go to the documentation of this file.
00001 //# SPolynomial.h: A one dimensional scaled polynomial class
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: SPolynomial.h 21024 2011-03-01 11:46:18Z gervandiepen $
00027 
00028 #ifndef SCIMATH_SPOLYNOMIAL_H
00029 #define SCIMATH_SPOLYNOMIAL_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/SPolynomialParam.h>
00034 #include <scimath/Functionals/Function.h>
00035 #include <scimath/Mathematics/AutoDiff.h>
00036 #include <scimath/Mathematics/AutoDiffMath.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward declarations
00041 
00042 // <summary> A one dimensional scaled polynomial class
00043 // </summary>
00044 
00045 // <reviewed reviewer="" date="" tests="tSPolynomial"
00046 // demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class=Function>Function</linkto>
00051 // </prerequisite>
00052 //
00053 // <synopsis> 
00054 // A SPolynomial<T> contains a set of coefficients; its fundamental operations
00055 // is evaluating itself at some "x". The number of coefficients is the order
00056 // of the polynomial plus one, plus an additional 3 as height, center, width.
00057 //
00058 // </synopsis> 
00059 //
00060 // <example>
00061 // <srcblock>
00062 //  SPolynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default
00063 //  pf.setCoefficient(1, 1.0);
00064 //  pf[5] = 2.0;
00065 //  pf.setCoefficient(3, 3.0);  // 3x^3 + 2x^2 + x
00066 //  pf(2); // == 34
00067 // </srcblock>
00068 // </example>
00069 
00070 // <templating arg=T>
00071 //  <li> T should have standard numerical operators. Current
00072 //      implementation only tested for real types (and their AutoDiffs).
00073 // </templating>
00074 
00075 // <thrown>
00076 //    <li> Assertion in debug mode if attempt is made to address incorrect
00077 //              coefficients
00078 // </thrown>
00079 
00080 // <todo asof="2002/05/20">
00081 //   <li> Nothing I know of
00082 // </todo>
00083 
00084 template<class T> class SPolynomial: public SPolynomialParam<T>
00085 {
00086 public:
00087   //# Enumerations
00088   
00089   //# Constructors
00090   // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
00091   SPolynomial() : SPolynomialParam<T>() {}
00092   // Makes a polynomial of the given order, with all coeficcients set to
00093   // zero, and height, center, width to 1,0,1.
00094   explicit SPolynomial(uInt order) : SPolynomialParam<T>(order) {}
00095   // Copy constructor/assignment (deep copy)
00096   // <group>
00097   SPolynomial(const SPolynomial<T> &other) : SPolynomialParam<T>(other) {}
00098   template <class W>
00099     SPolynomial(const SPolynomial<W> &other) : SPolynomialParam<T>(other) {}
00100   SPolynomial<T> &operator=(const SPolynomial<T> &other) {
00101     SPolynomialParam<T>::operator=(other); return *this; }
00102   // </group>
00103   
00104   // Destructor
00105   virtual ~SPolynomial() {}
00106   
00107   //# Operators    
00108   // Evaluate the polynomial at <src>x</src>.
00109   virtual T eval(typename Function<T>::FunctionArg x) const;
00110   
00111   //# Member functions
00112   
00113   // Return a copy of this object from the heap. The caller is responsible for
00114   // deleting the pointer.
00115   // <group>
00116   virtual Function<T> *clone() const { return new SPolynomial<T>(*this); }
00117   virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
00118     return new SPolynomial<typename FunctionTraits<T>::DiffType>(*this); }
00119   virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
00120     return new SPolynomial<typename FunctionTraits<T>::BaseType>(*this); }
00121   // </group>
00122 
00123   //# Make members of parent classes known.
00124 protected:
00125   using SPolynomialParam<T>::param_p;
00126 public:
00127   using SPolynomialParam<T>::nparameters;
00128   using SPolynomialParam<T>::mask;
00129 };
00130 
00131 
00132 } //# NAMESPACE CASA - END
00133 
00134 #ifndef CASACORE_NO_AUTO_TEMPLATES
00135 #include <scimath/Functionals/SPolynomial.tcc>
00136 #endif //# CASACORE_NO_AUTO_TEMPLATES
00137 #endif