Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:13:55

0001 // @(#)root/mathmore:$Id$
0002 // Authors: L. Moneta, A. Zsenei   08/2005
0003 
0004  /**********************************************************************
0005   *                                                                    *
0006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
0007   *                                                                    *
0008   * This library is free software; you can redistribute it and/or      *
0009   * modify it under the terms of the GNU General Public License        *
0010   * as published by the Free Software Foundation; either version 2     *
0011   * of the License, or (at your option) any later version.             *
0012   *                                                                    *
0013   * This library is distributed in the hope that it will be useful,    *
0014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
0015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
0016   * General Public License for more details.                           *
0017   *                                                                    *
0018   * You should have received a copy of the GNU General Public License  *
0019   * along with this library (see file COPYING); if not, write          *
0020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
0021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
0022   *                                                                    *
0023   **********************************************************************/
0024 
0025 // Header file for class ChebyshevApprox
0026 //
0027 // Created by: moneta  at Thu Dec  2 14:51:15 2004
0028 //
0029 // Last update: Thu Dec  2 14:51:15 2004
0030 //
0031 #ifndef ROOT_Math_ChebyshevApprox
0032 #define ROOT_Math_ChebyshevApprox
0033 
0034 
0035 
0036 /**
0037    @defgroup FuncApprox Function Approximation (ChebyshevApprox)
0038    Numerical algorithm from the \ref MathMore library and implemented using the
0039    <A HREF="http://www.gnu.org/software/gsl/manual/html_node/">GSL</A> library
0040  
0041    @ingroup NumAlgo
0042  */
0043 
0044 
0045 #include "Math/IFunctionfwd.h"
0046 
0047 #include "Math/GSLFunctionAdapter.h"
0048 
0049 #include <utility>
0050 #include <cstddef>
0051 
0052 
0053 namespace ROOT {
0054 namespace Math {
0055 
0056 class GSLChebSeries;
0057 class GSLFunctionWrapper;
0058 
0059 //____________________________________________________________________________
0060 /**
0061    Class describing a Chebyshev series which can be used to approximate a
0062    function in a defined range [a,b] using Chebyshev polynomials.
0063    It uses the algorithm from
0064    <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Chebyshev-Approximations.html">GSL</A>
0065 
0066    This class does not support copying
0067    @ingroup FuncApprox
0068  */
0069 
0070 
0071 class ChebyshevApprox {
0072 
0073 public:
0074 
0075 
0076    /**
0077       Construct a Chebyshev series approximation to a Function f in range [a,b];
0078       constructor based on functions of type IGenFunction
0079    */
0080 
0081   ChebyshevApprox(const ROOT::Math::IGenFunction & f, double a, double b, size_t n);
0082 
0083    /**
0084       Construct a Chebyshev series approximation to a Function f in range [a,b];
0085       constructor based on free functions with gsl_function type signature
0086    */
0087    ChebyshevApprox(GSLFuncPointer f, void *p, double a, double b, size_t n);
0088 
0089    // destructor
0090    virtual ~ChebyshevApprox();
0091 
0092 
0093 private:
0094 
0095    /**
0096       construct a Chebyshev series or order n
0097       The series must be initialized from a function
0098    */
0099    ChebyshevApprox(size_t n);
0100 
0101 public:
0102 
0103 // usually copying is non trivial, so we delete this
0104    ChebyshevApprox(const ChebyshevApprox &) = delete;
0105    ChebyshevApprox & operator = (const ChebyshevApprox &) = delete;
0106    ChebyshevApprox(ChebyshevApprox &&) = delete;
0107    ChebyshevApprox & operator = (ChebyshevApprox &&) = delete;
0108 
0109    /**
0110        Evaluate the series at a given point x
0111    */
0112    double operator() ( double x) const;
0113 
0114    /**
0115       Evaluate the series at a given point x estimating both the series result and its absolute error.
0116       The error estimate is made from the first neglected term in the series.
0117       A pair containing result and error is returned
0118    */
0119    std::pair<double, double>  EvalErr( double x) const;
0120 
0121    /**
0122       Evaluate the series at a given point, to (at most) the given order n
0123    */
0124    double operator() ( double x, size_t n) const;
0125 
0126    /**
0127       evaluate the series at a given point x to the given order n,
0128       estimating both the series result and its absolute error.
0129       The error estimate is made from the first neglected term in the series.
0130       A pair containing result and error is returned
0131    */
0132    std::pair<double, double>  EvalErr( double x, size_t n) const;
0133 
0134    /**
0135       Compute the derivative of the series and return a pointer to a new Chebyshev series with the
0136       derivatives coefficients. The returned pointer must be managed by the user.
0137    */
0138    //TO DO: implement copying to return by value
0139    ChebyshevApprox * Deriv();
0140 
0141    /**
0142       Compute the integral of the series and return a pointer to a new Chebyshev series with the
0143       integral coefficients. The lower limit of the integration is the left range value a.
0144       The returned pointer must be managed by the user
0145    */
0146    //TO DO: implement copying to return by value
0147    ChebyshevApprox * Integral();
0148 
0149 protected:
0150 
0151    /**
0152        Initialize series passing function and range
0153    */
0154    void Initialize( GSLFuncPointer f, void * params, double a, double b);
0155 
0156 private:
0157 
0158    size_t fOrder;
0159 
0160    GSLChebSeries * fSeries;
0161    GSLFunctionWrapper * fFunction;     // pointer to function
0162 
0163 };
0164 
0165 } // namespace Math
0166 } // namespace ROOT
0167 
0168 #endif /* ROOT_Math_ChebyshevApprox */