00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "Math/IFunction.h"
00035
00036 #include "Math/Chebyshev.h"
00037 #include "GSLFunctionWrapper.h"
00038 #include "GSLChebSeries.h"
00039
00040 #include "gsl/gsl_chebyshev.h"
00041
00042 #include <cassert>
00043
00044
00045 namespace ROOT {
00046 namespace Math {
00047
00048
00049 Chebyshev::Chebyshev(const ROOT::Math::IGenFunction & f, double a, double b, size_t n) :
00050 fOrder(n) , fSeries(0), fFunction(0)
00051 {
00052
00053 fSeries = new GSLChebSeries(n);
00054 GSLFunctionAdapter<ROOT::Math::IGenFunction> adapter;
00055 const void * p = &f;
00056 Initialize( &adapter.F, const_cast<void *>(p), a, b );
00057 }
00058
00059
00060 Chebyshev::Chebyshev(GSLFuncPointer f, void * params, double a, double b, size_t n) :
00061 fOrder(n) , fSeries(0), fFunction(0)
00062 {
00063
00064 fSeries = new GSLChebSeries(n);
00065 Initialize( f, params, a, b );
00066 }
00067
00068 Chebyshev::~Chebyshev()
00069 {
00070
00071 if (fFunction) delete fFunction;
00072 if (fSeries) delete fSeries;
00073 }
00074
00075 Chebyshev::Chebyshev(size_t n) :
00076 fOrder(n) , fSeries(0), fFunction(0)
00077 {
00078
00079 fSeries = new GSLChebSeries(n);
00080 }
00081
00082 Chebyshev::Chebyshev(const Chebyshev & )
00083 {
00084
00085 }
00086
00087 Chebyshev & Chebyshev::operator = (const Chebyshev &rhs)
00088 {
00089
00090 if (this == &rhs) return *this;
00091
00092 return *this;
00093 }
00094
00095 void Chebyshev::Initialize( GSLFuncPointer f, void * params, double a, double b) {
00096
00097
00098 assert(fSeries != 0);
00099 if (fFunction) delete fFunction;
00100
00101 fFunction = new GSLFunctionWrapper();
00102 fFunction->SetFuncPointer( f );
00103 fFunction->SetParams( params );
00104
00105
00106 gsl_cheb_init( fSeries->get(), fFunction->GetFunc(), a, b);
00107 }
00108
00109 double Chebyshev::operator() ( double x ) const {
00110
00111 return gsl_cheb_eval(fSeries->get(), x);
00112 }
00113
00114 std::pair<double, double> Chebyshev::EvalErr( double x) const {
00115
00116 double result, error;
00117 gsl_cheb_eval_err(fSeries->get(), x, &result, &error);
00118 return std::make_pair( result, error);
00119 }
00120
00121 double Chebyshev::operator() ( double x, size_t n) const {
00122
00123 return gsl_cheb_eval_n(fSeries->get(), n, x);
00124 }
00125
00126 std::pair<double, double> Chebyshev::EvalErr( double x, size_t n) const {
00127
00128 double result, error;
00129 gsl_cheb_eval_n_err(fSeries->get(), n, x, &result, &error);
00130 return std::make_pair( result, error);
00131 }
00132
00133
00134
00135 Chebyshev * Chebyshev::Deriv() {
00136
00137
00138 Chebyshev * deriv = new Chebyshev(fOrder);
00139
00140
00141 gsl_cheb_calc_deriv( (deriv->fSeries)->get(), fSeries->get() );
00142 return deriv;
00143
00144
00145
00146 }
00147
00148 Chebyshev * Chebyshev::Integral() {
00149
00150 Chebyshev * integ = new Chebyshev(fOrder);
00151
00152
00153 gsl_cheb_calc_integ( (integ->fSeries)->get(), fSeries->get() );
00154 return integ;
00155
00156
00157 }
00158
00159 }
00160 }