// @(#)root/mathmore:$Id$
// Authors: L. Moneta, A. Zsenei   08/2005

/**********************************************************************
*                                                                    *
* Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
*                                                                    *
* This library is free software; you can redistribute it and/or      *
* modify it under the terms of the GNU General Public License        *
* as published by the Free Software Foundation; either version 2     *
* of the License, or (at your option) any later version.             *
*                                                                    *
* This library is distributed in the hope that it will be useful,    *
* but WITHOUT ANY WARRANTY; without even the implied warranty of     *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
* General Public License for more details.                           *
*                                                                    *
* You should have received a copy of the GNU General Public License  *
* along with this library (see file COPYING); if not, write          *
* to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
* 330, Boston, MA 02111-1307 USA, or contact the author.             *
*                                                                    *
**********************************************************************/

// Header file for class ChebyshevApprox
//
// Created by: moneta  at Thu Dec  2 14:51:15 2004
//
// Last update: Thu Dec  2 14:51:15 2004
//
#ifndef ROOT_Math_ChebyshevApprox
#define ROOT_Math_ChebyshevApprox

/**
@defgroup NumAlgo Numerical Algorithms
Numerical Algorithm mainly from the \ref MathMore and implemented using the
<A HREF="http://www.gnu.org/software/gsl/manual/html_node/">GSL</A> library
*/

/**
@defgroup FuncApprox Function Approximation (ChebyshevApprox)
@ingroup NumAlgo
*/

#ifndef ROOT_Math_IFunctionfwd
#include "Math/IFunctionfwd.h"
#endif

#endif

#include <memory>
#include <cstddef>

namespace ROOT {
namespace Math {

class GSLChebSeries;
class GSLFunctionWrapper;

//____________________________________________________________________________
/**
Class describing a Chebyshev series which can be used to approximate a
function in a defined range [a,b] using Chebyshev polynomials.
It uses the algorithm from
<A HREF="http://www.gnu.org/software/gsl/manual/html_node/Chebyshev-Approximations.html">GSL</A>

This class does not support copying
@ingroup FuncApprox
*/

class ChebyshevApprox {

public:

/**
Construct a Chebyshev series approximation to a Function f in range [a,b];
constructor based on functions of type IGenFunction
*/

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 free functions with gsl_function type signature
*/
ChebyshevApprox(GSLFuncPointer f, void *p, double a, double b, size_t n);

// destructor
virtual ~ChebyshevApprox();

private:

/**
construct a Chebyshev series or order n
The series must be initialized from a function
*/
ChebyshevApprox(size_t n);

// usually copying is non trivial, so we make this unaccessible
ChebyshevApprox(const ChebyshevApprox &);
ChebyshevApprox & operator = (const ChebyshevApprox &);

public:

/**
Evaluate the series at a given point x
*/
double operator() ( double x) const;

/**
Evaluate the series at a given point x estimating both the series result and its absolute error.
The error estimate is made from the first neglected term in the series.
A pair containing result and error is returned
*/
std::pair<double, double>  EvalErr( double x) const;

/**
Evaluate the series at a given point, to (at most) the given order n
*/
double operator() ( double x, size_t n) const;

/**
evaluate the series at a given point x to the given order n,
estimating both the series result and its absolute error.
The error estimate is made from the first neglected term in the series.
A pair containing result and error is returned
*/
std::pair<double, double>  EvalErr( double x, size_t n) const;

/**
Compute the derivative of the series and return a pointer to a new Chebyshev series with the
derivatives coefficients. The returned pointer must be managed by the user.
*/
//TO DO: implement copying to return by value
ChebyshevApprox * Deriv();

/**
Compute the integral of the series and return a pointer to a new Chebyshev series with the
integral coefficients. The lower limit of the integration is the left range value a.
The returned pointer must be managed by the user
*/
//TO DO: implement copying to return by value
ChebyshevApprox * Integral();

protected:

/**
Initialize series passing function and range
*/
void Initialize( GSLFuncPointer f, void * params, double a, double b);

private:

size_t fOrder;

GSLChebSeries * fSeries;
GSLFunctionWrapper * fFunction;     // pointer to function

};

} // namespace Math
} // namespace ROOT

#endif /* ROOT_Math_ChebyshevApprox */

ChebyshevApprox.h:1
ChebyshevApprox.h:2
ChebyshevApprox.h:3
ChebyshevApprox.h:4
ChebyshevApprox.h:5
ChebyshevApprox.h:6
ChebyshevApprox.h:7
ChebyshevApprox.h:8
ChebyshevApprox.h:9
ChebyshevApprox.h:10
ChebyshevApprox.h:11
ChebyshevApprox.h:12
ChebyshevApprox.h:13
ChebyshevApprox.h:14
ChebyshevApprox.h:15
ChebyshevApprox.h:16
ChebyshevApprox.h:17
ChebyshevApprox.h:18
ChebyshevApprox.h:19
ChebyshevApprox.h:20
ChebyshevApprox.h:21
ChebyshevApprox.h:22
ChebyshevApprox.h:23
ChebyshevApprox.h:24
ChebyshevApprox.h:25
ChebyshevApprox.h:26
ChebyshevApprox.h:27
ChebyshevApprox.h:28
ChebyshevApprox.h:29
ChebyshevApprox.h:30
ChebyshevApprox.h:31
ChebyshevApprox.h:32
ChebyshevApprox.h:33
ChebyshevApprox.h:34
ChebyshevApprox.h:35
ChebyshevApprox.h:36
ChebyshevApprox.h:37
ChebyshevApprox.h:38
ChebyshevApprox.h:39
ChebyshevApprox.h:40
ChebyshevApprox.h:41
ChebyshevApprox.h:42
ChebyshevApprox.h:43
ChebyshevApprox.h:44
ChebyshevApprox.h:45
ChebyshevApprox.h:46
ChebyshevApprox.h:47
ChebyshevApprox.h:48
ChebyshevApprox.h:49
ChebyshevApprox.h:50
ChebyshevApprox.h:51
ChebyshevApprox.h:52
ChebyshevApprox.h:53
ChebyshevApprox.h:54
ChebyshevApprox.h:55
ChebyshevApprox.h:56
ChebyshevApprox.h:57
ChebyshevApprox.h:58
ChebyshevApprox.h:59
ChebyshevApprox.h:60
ChebyshevApprox.h:61
ChebyshevApprox.h:62
ChebyshevApprox.h:63
ChebyshevApprox.h:64
ChebyshevApprox.h:65
ChebyshevApprox.h:66
ChebyshevApprox.h:67
ChebyshevApprox.h:68
ChebyshevApprox.h:69
ChebyshevApprox.h:70
ChebyshevApprox.h:71
ChebyshevApprox.h:72
ChebyshevApprox.h:73
ChebyshevApprox.h:74
ChebyshevApprox.h:75
ChebyshevApprox.h:76
ChebyshevApprox.h:77
ChebyshevApprox.h:78
ChebyshevApprox.h:79
ChebyshevApprox.h:80
ChebyshevApprox.h:81
ChebyshevApprox.h:82
ChebyshevApprox.h:83
ChebyshevApprox.h:84
ChebyshevApprox.h:85
ChebyshevApprox.h:86
ChebyshevApprox.h:87
ChebyshevApprox.h:88
ChebyshevApprox.h:89
ChebyshevApprox.h:90
ChebyshevApprox.h:91
ChebyshevApprox.h:92
ChebyshevApprox.h:93
ChebyshevApprox.h:94
ChebyshevApprox.h:95
ChebyshevApprox.h:96
ChebyshevApprox.h:97
ChebyshevApprox.h:98
ChebyshevApprox.h:99
ChebyshevApprox.h:100
ChebyshevApprox.h:101
ChebyshevApprox.h:102
ChebyshevApprox.h:103
ChebyshevApprox.h:104
ChebyshevApprox.h:105
ChebyshevApprox.h:106
ChebyshevApprox.h:107
ChebyshevApprox.h:108
ChebyshevApprox.h:109
ChebyshevApprox.h:110
ChebyshevApprox.h:111
ChebyshevApprox.h:112
ChebyshevApprox.h:113
ChebyshevApprox.h:114
ChebyshevApprox.h:115
ChebyshevApprox.h:116
ChebyshevApprox.h:117
ChebyshevApprox.h:118
ChebyshevApprox.h:119
ChebyshevApprox.h:120
ChebyshevApprox.h:121
ChebyshevApprox.h:122
ChebyshevApprox.h:123
ChebyshevApprox.h:124
ChebyshevApprox.h:125
ChebyshevApprox.h:126
ChebyshevApprox.h:127
ChebyshevApprox.h:128
ChebyshevApprox.h:129
ChebyshevApprox.h:130
ChebyshevApprox.h:131
ChebyshevApprox.h:132
ChebyshevApprox.h:133
ChebyshevApprox.h:134
ChebyshevApprox.h:135
ChebyshevApprox.h:136
ChebyshevApprox.h:137
ChebyshevApprox.h:138
ChebyshevApprox.h:139
ChebyshevApprox.h:140
ChebyshevApprox.h:141
ChebyshevApprox.h:142
ChebyshevApprox.h:143
ChebyshevApprox.h:144
ChebyshevApprox.h:145
ChebyshevApprox.h:146
ChebyshevApprox.h:147
ChebyshevApprox.h:148
ChebyshevApprox.h:149
ChebyshevApprox.h:150
ChebyshevApprox.h:151
ChebyshevApprox.h:152
ChebyshevApprox.h:153
ChebyshevApprox.h:154
ChebyshevApprox.h:155
ChebyshevApprox.h:156
ChebyshevApprox.h:157
ChebyshevApprox.h:158
ChebyshevApprox.h:159
ChebyshevApprox.h:160
ChebyshevApprox.h:161
ChebyshevApprox.h:162
ChebyshevApprox.h:163
ChebyshevApprox.h:164
ChebyshevApprox.h:165
ChebyshevApprox.h:166
ChebyshevApprox.h:167
ChebyshevApprox.h:168
ChebyshevApprox.h:169
ChebyshevApprox.h:170
ChebyshevApprox.h:171
ChebyshevApprox.h:172