00001 // @(#)root/mathmore:$Id: Chebyshev.h 38027 2011-02-10 11:47:00Z rdm $ 00002 // Authors: L. Moneta, A. Zsenei 08/2005 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU General Public License * 00010 * as published by the Free Software Foundation; either version 2 * 00011 * of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this library (see file COPYING); if not, write * 00020 * to the Free Software Foundation, Inc., 59 Temple Place, Suite * 00021 * 330, Boston, MA 02111-1307 USA, or contact the author. * 00022 * * 00023 **********************************************************************/ 00024 00025 // Header file for class Chebyshev 00026 // 00027 // Created by: moneta at Thu Dec 2 14:51:15 2004 00028 // 00029 // Last update: Thu Dec 2 14:51:15 2004 00030 // 00031 #ifndef ROOT_Math_Chebyshev 00032 #define ROOT_Math_Chebyshev 00033 00034 /** 00035 @defgroup NumAlgo Numerical Algorithms 00036 Numerical Algorithm mainly from the \ref MathMore and implemented using the 00037 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/">GSL</A> library 00038 */ 00039 00040 00041 /** 00042 @defgroup FuncApprox Function Approximation (Chebyshev) 00043 @ingroup NumAlgo 00044 */ 00045 00046 00047 #ifndef ROOT_Math_IFunctionfwd 00048 #include "Math/IFunctionfwd.h" 00049 #endif 00050 00051 #ifndef ROOT_Math_GSLFunctionAdapter 00052 #include "Math/GSLFunctionAdapter.h" 00053 #endif 00054 00055 #include <memory> 00056 #include <cstddef> 00057 00058 00059 namespace ROOT { 00060 namespace Math { 00061 00062 class GSLChebSeries; 00063 class GSLFunctionWrapper; 00064 00065 //____________________________________________________________________________ 00066 /** 00067 Class describing a Chebyshev series which can be used to approximate a 00068 function in a defined range [a,b] using Chebyshev polynomials. 00069 It uses the algorithm from 00070 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Chebyshev-Approximations.html">GSL</A> 00071 00072 This class does not support copying 00073 @ingroup FuncApprox 00074 */ 00075 00076 00077 class Chebyshev { 00078 00079 public: 00080 00081 00082 /** 00083 Construct a Chebyshev series approximation to a Function f in range [a,b]; 00084 constructor based on functions of type IGenFunction 00085 */ 00086 00087 Chebyshev(const ROOT::Math::IGenFunction & f, double a, double b, size_t n); 00088 00089 /** 00090 Construct a Chebyshev series approximation to a Function f in range [a,b]; 00091 constructor based on free functions with gsl_function type signature 00092 */ 00093 Chebyshev(GSLFuncPointer f, void *p, double a, double b, size_t n); 00094 00095 // destructor 00096 virtual ~Chebyshev(); 00097 00098 00099 private: 00100 00101 /** 00102 construct a Chebyshev series or order n 00103 The series must be initialized from a function 00104 */ 00105 Chebyshev(size_t n); 00106 00107 // usually copying is non trivial, so we make this unaccessible 00108 Chebyshev(const Chebyshev &); 00109 Chebyshev & operator = (const Chebyshev &); 00110 00111 public: 00112 00113 /** 00114 Evaluate the series at a given point x 00115 */ 00116 double operator() ( double x) const; 00117 00118 /** 00119 Evaluate the series at a given point x estimating both the series result and its absolute error. 00120 The error estimate is made from the first neglected term in the series. 00121 A pair containing result and error is returned 00122 */ 00123 std::pair<double, double> EvalErr( double x) const; 00124 00125 /** 00126 Evaluate the series at a given point, to (at most) the given order n 00127 */ 00128 double operator() ( double x, size_t n) const; 00129 00130 /** 00131 evaluate the series at a given point x to the given order n, 00132 estimating both the series result and its absolute error. 00133 The error estimate is made from the first neglected term in the series. 00134 A pair containing result and error is returned 00135 */ 00136 std::pair<double, double> EvalErr( double x, size_t n) const; 00137 00138 /** 00139 Compute the derivative of the series and return a pointer to a new Chebyshev series with the 00140 derivatives coefficients. The returned pointer must be managed by the user. 00141 */ 00142 //TO DO: implement copying to return by value 00143 Chebyshev * Deriv(); 00144 00145 /** 00146 Compute the integral of the series and return a pointer to a new Chebyshev series with the 00147 integral coefficients. The lower limit of the integration is the left range value a. 00148 The returned pointer must be managed by the user 00149 */ 00150 //TO DO: implement copying to return by value 00151 Chebyshev * Integral(); 00152 00153 protected: 00154 00155 /** 00156 Initialize series passing function and range 00157 */ 00158 void Initialize( GSLFuncPointer f, void * params, double a, double b); 00159 00160 private: 00161 00162 size_t fOrder; 00163 00164 GSLChebSeries * fSeries; 00165 GSLFunctionWrapper * fFunction; // pointer to function 00166 00167 }; 00168 00169 } // namespace Math 00170 } // namespace ROOT 00171 00172 #endif /* ROOT_Math_Chebyshev */