Main Page | Alphabetical List | Class List | File List | Class Members | File Members

Chebyshev.h

Go to the documentation of this file.
00001 #ifndef CHEBYSHEV_H
00002 #define CHEBYSHEV_H
00003 
00004 
00005 // ----------------------------------------------------------------------
00006 //
00007 // Bridge object between C++ code and the gsl Chebyshev expansion code
00008 //
00009 // ----------------------------------------------------------------------
00010 
00011 #ifndef ZMENVIRONMENT_H
00012 #include "ZMutility/ZMenvironment.h"
00013 #endif
00014 #include <utility>
00015 #include <vector>
00016 #include <string>
00017 #include "gsl/gsl_math.h"
00018 
00019 #include "SpecialFunctions/checkStatus.h"
00020 #include "SpecialFunctions/gsl_chebyshev.h"
00021 USING(std::string)
00022 
00023 ZM_BEGIN_NAMESPACE( zmsf )      /*  namespace zmsf  {  */
00024 
00025 typedef std::vector<double> Dvector;
00026 typedef std::pair<double,double> Dpair;
00027 
00031 
00032 
00040 template<class UserFcnT>
00041 struct UF { static UserFcnT* uf; };
00042 
00043 template<class UserFcnT> UserFcnT* UF<UserFcnT>::uf = 0;
00044 
00045 template<class UserFcnT>
00046 double proxy( double x ) {
00047   return (*UF<UserFcnT>::uf)(x);
00048 }
00049 
00050 template<class UserFcnT >
00051 double proxy2( double x, Dvector pars ) {
00052   return (*UF<UserFcnT>::uf)(x, pars);
00053 }
00054 
00059 
00060 class Chebyshev {
00061 
00062 public:
00063 
00065   Chebyshev();
00066 
00068   Chebyshev( const int order );
00069 
00071   Chebyshev( const string& filename );
00072   
00074 
00078   template<class UserFcnT>
00079   Chebyshev( UserFcnT f, const double a, const double b, const int order )
00080   {
00081     string fName = "Chebyshev::Chebyshev( UserFcnT f, a, b, order )";
00082     _series = gsl_cheb_alloc( order );
00083     if( _series == 0 )  checkStatus( GSL_ENOMEM, fName );
00084     UF<UserFcnT>::uf = &f;
00085     checkStatus( gsl_cheb_init( _series, &proxy<UserFcnT>, a, b ), fName );
00086   }
00087 
00089 
00094   template<class UserFcnT>
00095   Chebyshev( UserFcnT f, Dvector pars,
00096              const double a, const double b, const int order )
00097   {
00098     string fName = "Chebyshev::Chebyshev( UserFcnT f, pars, a, b, order )";
00099     _series = gsl_cheb_alloc( order );
00100     if( _series == 0 )  checkStatus( GSL_ENOMEM, fName );
00101     UF<UserFcnT>::uf = &f;
00102     checkStatus( gsl_cheb_init( _series, &proxy2<UserFcnT>, pars, a, b ), fName );
00103   }
00104 
00106   Chebyshev( const Chebyshev& F );
00107 
00109   Chebyshev& operator=(const Chebyshev& F );
00110 
00112   ~Chebyshev();
00113 
00115 
00119   template<class UserFcnT>
00120   void Expand( UserFcnT f, const double a, const double b, const int order )
00121   {
00122     string fName = "Chebyshev::Expand";
00123     gsl_cheb_free( _series );
00124     _series = gsl_cheb_alloc( order );
00125     if( _series == 0 )  checkStatus( GSL_ENOMEM, fName );
00126     UF<UserFcnT>::uf = &f;
00127     checkStatus( gsl_cheb_init( _series, &proxy<UserFcnT>, a, b ), fName );
00128   }
00129 
00131 
00135   template<class UserFcnT>
00136   void Expand( UserFcnT f, Dvector pars,
00137                const double a, const double b, const int order )
00138   {
00139     string fName = "Chebyshev::Expand";
00140     gsl_cheb_free( _series );
00141     _series = gsl_cheb_alloc( order );
00142     if( _series == 0 )  checkStatus( GSL_ENOMEM, fName );
00143     UF<UserFcnT>::uf = &f;
00144     checkStatus( gsl_cheb_init( _series, &proxy2<UserFcnT>, pars, a, b ), fName );
00145   }
00146 
00148   double EvaluateF( const double x );
00149 
00151   double operator () ( const double x );
00152 
00154   Dpair EvaluateFErr( const double x );
00155 
00157   double EvaluateFSingle( const double x );
00158 
00160   double EvaluateFN( const int order, const double x );
00161 
00163 
00167   Dpair EvaluateFNErr( const int order, const double x );
00168 
00170 
00176   Chebyshev Differentiate();
00177 
00179 
00186   Chebyshev Integrate();
00187 
00189   int GetOrder();
00190 
00192   Dpair GetInterval();
00193 
00195 
00199   Dvector GetExpansion();
00200 
00202   void SaveExpansion( const string& filename );
00203 
00204 private:
00205 
00206   static double fdummy( double x ) { return (1.0+x); };
00207 
00208   gsl_cheb_series *     _series;
00209 
00210 };  // Chebyshev
00211 
00212 
00213 ZM_END_NAMESPACE( zmsf )        /*  }  // namespace zmsf  */
00214 
00215 #endif  /* CHEBYSHEV_H */

Generated on Wed Feb 25 15:03:16 2004 for SpecialFunctions by doxygen 1.3.4