Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:01

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 // usually copying is non trivial, so we make this unaccessible
0102    ChebyshevApprox(const ChebyshevApprox &);
0103    ChebyshevApprox & operator = (const ChebyshevApprox &);
0104 
0105 public:
0106 
0107    /**
0108        Evaluate the series at a given point x
0109    */
0110    double operator() ( double x) const;
0111 
0112    /**
0113       Evaluate the series at a given point x estimating both the series result and its absolute error.
0114       The error estimate is made from the first neglected term in the series.
0115       A pair containing result and error is returned
0116    */
0117    std::pair<double, double>  EvalErr( double x) const;
0118 
0119    /**
0120       Evaluate the series at a given point, to (at most) the given order n
0121    */
0122    double operator() ( double x, size_t n) const;
0123 
0124    /**
0125       evaluate the series at a given point x to the given order n,
0126       estimating both the series result and its absolute error.
0127       The error estimate is made from the first neglected term in the series.
0128       A pair containing result and error is returned
0129    */
0130    std::pair<double, double>  EvalErr( double x, size_t n) const;
0131 
0132    /**
0133       Compute the derivative of the series and return a pointer to a new Chebyshev series with the
0134       derivatives coefficients. The returned pointer must be managed by the user.
0135    */
0136    //TO DO: implement copying to return by value
0137    ChebyshevApprox * Deriv();
0138 
0139    /**
0140       Compute the integral of the series and return a pointer to a new Chebyshev series with the
0141       integral coefficients. The lower limit of the integration is the left range value a.
0142       The returned pointer must be managed by the user
0143    */
0144    //TO DO: implement copying to return by value
0145    ChebyshevApprox * Integral();
0146 
0147 protected:
0148 
0149    /**
0150        Initialize series passing function and range
0151    */
0152    void Initialize( GSLFuncPointer f, void * params, double a, double b);
0153 
0154 private:
0155 
0156    size_t fOrder;
0157 
0158    GSLChebSeries * fSeries;
0159    GSLFunctionWrapper * fFunction;     // pointer to function
0160 
0161 };
0162 
0163 } // namespace Math
0164 } // namespace ROOT
0165 
0166 #endif /* ROOT_Math_ChebyshevApprox */