40 #include "gsl/gsl_chebyshev.h"
49 ChebyshevApprox::ChebyshevApprox(
const ROOT::Math::IGenFunction & f,
double a,
double b,
size_t n) :
50 fOrder(n) , fSeries(0), fFunction(0)
53 fSeries =
new GSLChebSeries(n);
54 GSLFunctionAdapter<ROOT::Math::IGenFunction> adapter;
56 Initialize( &adapter.F, const_cast<void *>(p), a, b );
60 ChebyshevApprox::ChebyshevApprox(GSLFuncPointer f,
void * params,
double a,
double b,
size_t n) :
61 fOrder(n) , fSeries(0), fFunction(0)
64 fSeries =
new GSLChebSeries(n);
65 Initialize( f, params, a, b );
68 ChebyshevApprox::~ChebyshevApprox()
71 if (fFunction)
delete fFunction;
72 if (fSeries)
delete fSeries;
75 ChebyshevApprox::ChebyshevApprox(
size_t n) :
76 fOrder(n) , fSeries(0), fFunction(0)
79 fSeries =
new GSLChebSeries(n);
82 ChebyshevApprox::ChebyshevApprox(
const ChebyshevApprox & )
87 ChebyshevApprox & ChebyshevApprox::operator = (
const ChebyshevApprox &rhs)
90 if (
this == &rhs)
return *
this;
95 void ChebyshevApprox::Initialize( GSLFuncPointer f,
void * params,
double a,
double b) {
99 if (fFunction)
delete fFunction;
101 fFunction =
new GSLFunctionWrapper();
102 fFunction->SetFuncPointer( f );
103 fFunction->SetParams( params );
106 gsl_cheb_init( fSeries->get(), fFunction->GetFunc(), a, b);
109 double ChebyshevApprox::operator() (
double x )
const {
111 return gsl_cheb_eval(fSeries->get(), x);
114 std::pair<double, double> ChebyshevApprox::EvalErr(
double x)
const {
116 double result, error;
117 gsl_cheb_eval_err(fSeries->get(), x, &result, &error);
118 return std::make_pair( result, error);
121 double ChebyshevApprox::operator() (
double x,
size_t n)
const {
123 return gsl_cheb_eval_n(fSeries->get(), n, x);
126 std::pair<double, double> ChebyshevApprox::EvalErr(
double x,
size_t n)
const {
128 double result, error;
129 gsl_cheb_eval_n_err(fSeries->get(), n, x, &result, &error);
130 return std::make_pair( result, error);
133 ChebyshevApprox *ChebyshevApprox::Deriv()
136 ChebyshevApprox *deriv =
new ChebyshevApprox(fOrder);
139 gsl_cheb_calc_deriv((deriv->fSeries)->get(), fSeries->get());
143 ChebyshevApprox *ChebyshevApprox::Integral()
146 ChebyshevApprox *integ =
new ChebyshevApprox(fOrder);
149 gsl_cheb_calc_integ((integ->fSeries)->get(), fSeries->get());