Logo ROOT  
Reference Guide
ChebyshevApprox.cxx
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Authors: L. Moneta, A. Zsenei 08/2005
3
4
5 /**********************************************************************
6 * *
7 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
8 * *
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public License *
11 * as published by the Free Software Foundation; either version 2 *
12 * of the License, or (at your option) any later version. *
13 * *
14 * This library is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
17 * General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this library (see file COPYING); if not, write *
21 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
22 * 330, Boston, MA 02111-1307 USA, or contact the author. *
23 * *
24 **********************************************************************/
25
26// Implementation file for class ChebyshevApprox
27//
28// Created by: moneta at Thu Dec 2 14:51:15 2004
29//
30// Last update: Thu Dec 2 14:51:15 2004
31//
32
33
34#include "Math/IFunction.h"
35
37#include "GSLFunctionWrapper.h"
38#include "GSLChebSeries.h"
39
40#include "gsl/gsl_chebyshev.h"
41
42#include <cassert>
43
44
45namespace ROOT {
46namespace Math {
47
48
50 fOrder(n) , fSeries(0), fFunction(0)
51{
52 // constructor from function (IGenFunction type) and interval [a,b] and series size n
53 fSeries = new GSLChebSeries(n);
55 const void * p = &f;
56 Initialize( &adapter.F, const_cast<void *>(p), a, b );
57}
58
59// constructor with GSL function
60ChebyshevApprox::ChebyshevApprox(GSLFuncPointer f, void * params, double a, double b, size_t n) :
61fOrder(n) , fSeries(0), fFunction(0)
62{
63 // constructor from function (GSL type) and interval [a,b] and series size n
64 fSeries = new GSLChebSeries(n);
65 Initialize( f, params, a, b );
66}
67
69{
70 // desctructor (clean up resources)
71 if (fFunction) delete fFunction;
72 if (fSeries) delete fSeries;
73}
74
76fOrder(n) , fSeries(0), fFunction(0)
77{
78 // constructor passing only size (need to initialize setting the function afterwards)
79 fSeries = new GSLChebSeries(n);
80}
81
83{
84 // cannot copy series because don't know original function
85}
86
88{
89 // dummy assignment
90 if (this == &rhs) return *this; // time saving self-test
91
92 return *this;
93}
94
95void ChebyshevApprox::Initialize( GSLFuncPointer f, void * params, double a, double b) {
96 // initialize by passing a function and interval [a,b]
97 // delete previous existing function pointer
98 assert(fSeries != 0);
99 if (fFunction) delete fFunction;
100
103 fFunction->SetParams( params );
104
105 // check for errors here ???
106 gsl_cheb_init( fSeries->get(), fFunction->GetFunc(), a, b);
107}
108
109double ChebyshevApprox::operator() ( double x ) const {
110 // evaluate the approximation
111 return gsl_cheb_eval(fSeries->get(), x);
112}
113
114std::pair<double, double> ChebyshevApprox::EvalErr( double x) const {
115 // evaluate returning result and error
116 double result, error;
117 gsl_cheb_eval_err(fSeries->get(), x, &result, &error);
118 return std::make_pair( result, error);
119}
120
121double ChebyshevApprox::operator() ( double x, size_t n) const {
122 // evaluate at most order n ( truncate the series)
123 return gsl_cheb_eval_n(fSeries->get(), n, x);
124}
125
126std::pair<double, double> ChebyshevApprox::EvalErr( double x, size_t n) const {
127 // evaluate at most order n ( truncate the series) returning resutl + error
128 double result, error;
129 gsl_cheb_eval_n_err(fSeries->get(), n, x, &result, &error);
130 return std::make_pair( result, error);
131}
132
134{
135 // calculate derivative. Returns pointer to a new series
137
138 // check for errors ?
139 gsl_cheb_calc_deriv((deriv->fSeries)->get(), fSeries->get());
140 return deriv;
141}
142
144{
145 // integral (return pointer)
147
148 // check for errors ?
149 gsl_cheb_calc_integ((integ->fSeries)->get(), fSeries->get());
150 return integ;
151}
152
153} // namespace Math
154} // namespace ROOT
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
Class describing a Chebyshev series which can be used to approximate a function in a defined range [a...
ChebyshevApprox & operator=(const ChebyshevApprox &)
ChebyshevApprox * Integral()
Compute the integral of the series and return a pointer to a new Chebyshev series with the integral c...
std::pair< double, double > EvalErr(double x) const
Evaluate the series at a given point x estimating both the series result and its absolute error.
double operator()(double x) const
Evaluate the series at a given point x.
ChebyshevApprox(const ROOT::Math::IGenFunction &f, double a, double b, size_t n)
Construct a Chebyshev series approximation to a Function f in range [a,b]; constructor based on funct...
void Initialize(GSLFuncPointer f, void *params, double a, double b)
Initialize series passing function and range.
ChebyshevApprox * Deriv()
Compute the derivative of the series and return a pointer to a new Chebyshev series with the derivati...
GSLFunctionWrapper * fFunction
wrapper class for C struct gsl_cheb_series
Definition: GSLChebSeries.h:44
gsl_cheb_series * get() const
Definition: GSLChebSeries.h:63
Class for adapting any C++ functor class to C function pointers used by GSL.
static double F(double x, void *p)
Wrapper class to the gsl_function C structure.
void SetFuncPointer(GSLFuncPointer f)
set in the GSL C struct the pointer to the function evaluation
void SetParams(void *p)
set in the GSL C struct the extra-object pointer
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Namespace for new Math classes and functions.
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12