testChebyshev.cxx

Go to the documentation of this file.
00001 
00002 #include "Math/Chebyshev.h"
00003 #include "Math/IFunction.h"
00004 #include "Math/Functor.h"
00005 #include "Math/SpecFunc.h"
00006 
00007 //#include "MathCore/GSLIntegrator.h"
00008 
00009 #include <iostream> 
00010 #include <cmath>
00011 
00012 
00013 typedef double ( * FP ) ( double, void * ); 
00014 
00015 // function is a step function
00016 
00017 double myfunc ( double x, void * /* params */) {
00018   //double * p = reinterpret_cast<double *>( params); 
00019   if (x < 0.5) 
00020     return 0.25; 
00021   else 
00022     return 0.75; 
00023 }
00024 
00025 double gamma_func( double x, void *) 
00026 { 
00027   return  ROOT::Math::tgamma(x);
00028 }
00029 
00030 // gamma function
00031 class GammaFunction : public ROOT::Math::IGenFunction { 
00032   
00033 public: 
00034 
00035 
00036   ROOT::Math::IGenFunction * Clone() const { 
00037     return new GammaFunction();
00038   }
00039 
00040 private: 
00041 
00042   double DoEval ( double x) const { 
00043     return ROOT::Math::tgamma(x);
00044   }
00045 
00046 };
00047 
00048 
00049 int printCheb( const ROOT::Math::Chebyshev & c, double x0, double x1, FP func = 0 ) { 
00050 
00051   double dx = (x1-x0)/10;
00052   for ( double x = x0; x < x1; x+= dx ) { 
00053 
00054     double y = c(x); 
00055     double ey = c.EvalErr(x).second; 
00056     double y10 = c(x,10);
00057     double ey10 = c.EvalErr(x,10).second; 
00058     double fVal = 0;
00059     if (func) fVal = func(x,0);
00060     std::cout << " x = " << x << " true Val = " << fVal << " y = " << y << " +/- " << ey << "    y@10 = " << y10 << " +/- " << ey10 << std::endl; 
00061   }
00062 
00063 
00064 
00065   return 0; 
00066 }
00067 
00068 
00069 
00070 int main() { 
00071 
00072 
00073   // test with cos(x) + 1.0
00074   std::cout << "Test Cheb approx to step function :" << std::endl;
00075   ROOT::Math::Chebyshev c(myfunc, 0, 0., 1.0, 40); 
00076   printCheb(c, 0, 1, myfunc); 
00077   std::cout << "Test integral of step function :" << std::endl;
00078   ROOT::Math::Chebyshev *  cInteg = c.Integral();
00079   printCheb(*cInteg, 0., 1); 
00080   delete cInteg;
00081   
00082 
00083   std::cout << "Test Cheb approx to Gamma function :" << std::endl;
00084   GammaFunction gf;
00085   ROOT::Math::Chebyshev c2(gf, 1.0, 2.0, 40); 
00086   printCheb(c2, 1.0, 2.0,  gamma_func); 
00087   std::cout << "Test derivative of gammma :" << std::endl;
00088   ROOT::Math::Chebyshev * cDeriv = c2.Deriv();
00089   printCheb(*cDeriv, 1.0, 2.0); 
00090   delete cDeriv;
00091 
00092 
00093  
00094   return 0; 
00095 
00096 }
00097 

Generated on Tue Jul 5 14:34:58 2011 for ROOT_528-00b_version by  doxygen 1.5.1