proj home

Files   Classes   Functions   Hierarchy  

powerseries1D.h

Go to the documentation of this file.
00001 #ifndef POWERSERIES1D_H
00002 #define POWERSERIES1D_H
00003 
00004 
00005 typedef unsigned int uint;
00006 typedef unsigned int const uintc;
00007 
00016 template< typename T >
00017 class powerseries1D
00018 {
00019 public:
00020 
00022   uint N;
00023 
00025   T * ai;
00026 
00028   void construct( T * ai_, uintc N_ )
00029     { N=N_; ai=ai_; }
00030 
00032   powerseries1D()
00033     : N(0), ai(0) {}
00034 
00036   powerseries1D( T * ai_, uintc N_ )
00037     { construct(ai_,N_); }
00038 
00040   void operator()(T & val, T const t) const;
00041 
00043   T const operator()(T const t) const;
00044 
00046   void differentiate();
00047 
00050   void taylorseries();
00051 
00052 };
00053 
00054 //--------------------------------------------------------
00055 // Implementation
00056 
00057 
00058 template< typename T >
00059 void powerseries1D<T>::operator()(T & val, T const t) const
00060 {
00061   // ai[0] + t(ai[1] + t(ai[2] + t(...
00062   val = 0.0;
00063   for (uint i=0; i<N; ++i)
00064   {
00065     val *= t;
00066     val += ai[N-1-i];
00067   }
00068 }
00069 
00070 template< typename T >
00071 T const powerseries1D<T>::operator()(T const t) const
00072 {
00073   // ai[0] + t(ai[1] + t(ai[2] + t(...
00074   T val = (T)0.0;
00075   for (uint i=0; i<N; ++i)
00076   {
00077     val *= t;
00078     val += ai[N-1-i];
00079   }
00080 
00081   return val;
00082 }
00083 
00084 template< typename T >
00085 void powerseries1D<T>::differentiate()
00086 {
00087   for (uint i=1; i<N; ++i)
00088   {
00089     ai[i]*=i;
00090     ai[i-1] = ai[i];
00091   }
00092   ai[N-1] = (T)0.0;
00093 }
00094 
00095 template< typename T >
00096 void powerseries1D<T>::taylorseries()
00097 {
00098   T s = (T)2.0;
00099   for (uint i=2; i<N; ++i)
00100   {
00101     ai[i] /= s;
00102     s *= (i+1);
00103   }
00104 }
00105 
00106 
00107 #endif
00108 
00109 
00110 
00111 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8