Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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(nullptr), fFunction(nullptr)
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(nullptr), fFunction(nullptr)
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 // destructor (clean up resources)
71 if (fFunction) delete fFunction;
72 if (fSeries) delete fSeries;
73}
74
76fOrder(n) , fSeries(nullptr), fFunction(nullptr)
77{
78 // constructor passing only size (need to initialize setting the function afterwards)
79 fSeries = new GSLChebSeries(n);
80}
81
82void ChebyshevApprox::Initialize( GSLFuncPointer f, void * params, double a, double b) {
83 // initialize by passing a function and interval [a,b]
84 // delete previous existing function pointer
85 assert(fSeries != nullptr);
86 if (fFunction) delete fFunction;
87
90 fFunction->SetParams( params );
91
92 // check for errors here ???
93 gsl_cheb_init( fSeries->get(), fFunction->GetFunc(), a, b);
94}
95
96double ChebyshevApprox::operator() ( double x ) const {
97 // evaluate the approximation
98 return gsl_cheb_eval(fSeries->get(), x);
99}
100
101std::pair<double, double> ChebyshevApprox::EvalErr( double x) const {
102 // evaluate returning result and error
103 double result, error;
104 gsl_cheb_eval_err(fSeries->get(), x, &result, &error);
105 return std::make_pair( result, error);
106}
107
108double ChebyshevApprox::operator() ( double x, size_t n) const {
109 // evaluate at most order n ( truncate the series)
110 return gsl_cheb_eval_n(fSeries->get(), n, x);
111}
112
113std::pair<double, double> ChebyshevApprox::EvalErr( double x, size_t n) const {
114 // evaluate at most order n ( truncate the series) returning result + error
115 double result, error;
116 gsl_cheb_eval_n_err(fSeries->get(), n, x, &result, &error);
117 return std::make_pair( result, error);
118}
119
121{
122 // calculate derivative. Returns pointer to a new series
124
125 // check for errors ?
126 gsl_cheb_calc_deriv((deriv->fSeries)->get(), fSeries->get());
127 return deriv;
128}
129
131{
132 // integral (return pointer)
134
135 // check for errors ?
136 gsl_cheb_calc_integ((integ->fSeries)->get(), fSeries->get());
137 return integ;
138}
139
140} // namespace Math
141} // namespace ROOT
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Class describing a Chebyshev series which can be used to approximate a function in a defined range [a...
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
gsl_cheb_series * get() const
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:112
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...