FunctionBase.cxx
Go to the documentation of this file.
00001 
00012 // for truncation warning in debug mode
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "FunctionBase.h"
00018 
00019 #include <cassert>
00020 
00021 using std::string;
00022 using std::vector;
00023 
00024 namespace hippodraw {
00025 
00030 FunctionBase::FunctionBase ()
00031 {
00032   m_name = "nil";
00033 }
00034 
00038 FunctionBase::
00039 FunctionBase ( const FunctionBase & fb )
00040   : m_name ( fb.m_name ),
00041     m_parm_names ( fb.m_parm_names ),
00042     m_parms ( fb.m_parms )
00043 {
00044 }
00045 
00046 FunctionBase::~FunctionBase ()
00047 {
00048 }
00049 
00050 FunctionBase *
00051 FunctionBase::
00052 clone () const
00053 {
00054   assert ( false );
00055   return 0;
00056 }
00057 
00058 void
00059 FunctionBase::
00060 initialParameters ( const FunctionHelper * )
00061 {
00062 }
00063 
00064 void
00065 FunctionBase::
00066 setName ( const char * name )
00067 {
00068   m_name = name;
00069 }
00070 
00071 void FunctionBase::resize ()
00072 {
00073   assert ( ! m_parm_names.empty () );
00074 
00075   size_t size = m_parm_names.size ();
00076   m_parms.resize ( size );
00077 //   m_fixed.resize ( size, false );
00078 
00079 }
00080 
00081 const string & FunctionBase::name () const
00082 {
00083   return m_name;
00084 }
00085 
00086 const vector < string > & FunctionBase::parmNames ( ) const
00087 {
00088   return m_parm_names;
00089 }
00090 
00091 void
00092 FunctionBase::
00093 setParmNames ( const std::vector < std::string > & names )
00094 {
00095   m_parm_names = names;
00096   resize ();
00097 }
00098 
00099 const vector < double > & FunctionBase::getParameters () const
00100 {
00101   return m_parms;
00102 }
00103 
00104 void
00105 FunctionBase::
00106 setParameters ( const std::vector< double > & incr )
00107 {
00108   vector< double >::const_iterator it = incr.begin ();
00109   setParameters ( it );
00110 }
00111 
00112 vector < double > ::const_iterator
00113 FunctionBase::
00114 setParameters ( std::vector < double > :: const_iterator it )
00115 {
00116   unsigned int size = m_parms.size();
00117   for ( unsigned int i = 0; i < size; i++ ) {
00118     m_parms[i] = *it++;
00119   }
00120 
00121   return it;
00122 }
00123 
00124 bool
00125 FunctionBase::
00126 hasDerivatives () const
00127 {
00128   return true;
00129 }
00130 
00138 double FunctionBase::integrate ( double a, double b ) const
00139 {
00140   int n = 10;
00141   double h  = (b - a)/n;
00142   double x = a;
00143   double sumt = operator()( a ) / 2;
00144   
00145   for( int i = 1; i <=  n - 1; i++ )
00146     {
00147       x += h;
00148       sumt += operator()( x );
00149     }
00150   
00151   sumt = ( sumt + operator()( b ) / 2 ) * h;
00152   
00153   return sumt;
00154 }
00155 
00156 int FunctionBase::size () const
00157 {
00158   return m_parm_names.size ();
00159 }
00160 
00161 bool FunctionBase::isComposite () const
00162 {
00163   return false;
00164 }
00165 
00166 void FunctionBase::addToComposite ( FunctionBase * )
00167 {
00168 }
00169 
00170 void FunctionBase::removeFromComposite ( FunctionBase * )
00171 {
00172 }
00173 
00174 int FunctionBase::count()
00175 {
00176   return 0;
00177 }
00178 
00179 double
00180 FunctionBase::
00181 operator () ( const std::vector < double > & v ) const
00182 {
00183   assert ( v.size () == 1 );
00184 
00185   return this -> operator () ( v.front () );
00186 }
00187 
00188 double
00189 FunctionBase::
00190 derivByParm ( int, double ) const
00191 {
00192         assert ( false );
00193         return 0.;
00194 }
00195 
00196 void
00197 FunctionBase::
00198 initialize ()
00199 {
00200         assert ( false );
00201 }
00202 
00203 double
00204 FunctionBase::
00205 operator () ( double ) const
00206 {
00207         assert ( false );
00208         return 0.;
00209 }
00210 
00211 unsigned int
00212 FunctionBase::
00213 dimensions () const
00214 {
00215   return 1;
00216 }
00217 
00218 } // namespace hippodraw
00219 

Generated for HippoDraw Class Library by doxygen