Object-oriented Scientific Computing Library: Version 0.910
cern_gauss56.h
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl 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
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef O2SCL_CERN_GAUSS56_H
00024 #define O2SCL_CERN_GAUSS56_H
00025 
00026 #include <o2scl/inte.h>
00027  
00028 #ifndef DOXYGENP
00029 namespace o2scl {
00030 #endif
00031 
00032   /** \brief 5,6-point Gaussian quadrature (CERNLIB)
00033       
00034       If \f$ I_5 \f$ is the 5-point approximation, and \f$ I_6 \f$ is the
00035       6-point approximation to the integral, then integ_err() returns
00036       the result \f$ \frac{1}{2}(I_5+I_6) \f$ with uncertainty
00037       \f$ |I_5-I_6| \f$.
00038 
00039       This class is based on the CERNLIB routines RGS56P and
00040       DGS56P which are documented at
00041       http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/d106/top.html
00042 
00043   */
00044   template<class func_t> class cern_gauss56 : public inte<func_t>  {
00045 
00046   public:
00047   
00048     cern_gauss56() {
00049       x5[0]=4.6910077030668004e-02;
00050       w5[0]=1.1846344252809454e-01;
00051       x5[1]=2.3076534494715846e-01;
00052       w5[1]=2.3931433524968324e-01;
00053       x5[2]=5.0000000000000000e-01;
00054       w5[2]=2.8444444444444444e-01;
00055       x5[3]=7.6923465505284154e-01;
00056       w5[3]=2.3931433524968324e-01;
00057       x5[4]=9.5308992296933200e-01;
00058       w5[4]=1.1846344252809454e-01;
00059  
00060       x6[0]=3.3765242898423989e-02;
00061       w6[0]=8.5662246189585178e-02;
00062       x6[1]=1.6939530676686775e-01;
00063       w6[1]=1.8038078652406930e-01;
00064       x6[2]=3.8069040695840155e-01;
00065       w6[2]=2.3395696728634552e-01;
00066       x6[3]=6.1930959304159845e-01;
00067       w6[3]=2.3395696728634552e-01;
00068       x6[4]=8.3060469323313225e-01;
00069       w6[4]=1.8038078652406930e-01;
00070       x6[5]=9.6623475710157601e-01;
00071       w6[5]=8.5662246189585178e-02;
00072     }
00073 
00074     /** \brief Integrate function \c func from \c a to \c b
00075         giving result \c res and error \c err
00076 
00077         This function always returns \ref gsl_success.
00078     */
00079     virtual int integ_err(func_t &func, double a, double b,
00080                           double &res, double &err) {
00081 
00082       double rang=b-a, e5=0.0, e6=0.0, ytmp;
00083 
00084       for(int i=0;i<5;i++) {
00085         ytmp=func(a+rang*x5[i]);
00086         e5+=w5[i]*ytmp;
00087         ytmp=func(a+rang*x6[i]);
00088         e6+=w6[i]*ytmp;
00089       }
00090       ytmp=func(a+rang*x6[5]);
00091       e6+=w6[5]*ytmp;
00092       res=(e6+e5)*rang/2.0;
00093       err=fabs((e6-e5)*rang);
00094 
00095       return gsl_success;
00096     }
00097 
00098   protected:
00099 
00100 #ifndef DOXYGEN_INTERNAL
00101 
00102     /** \name Integration constants
00103     */
00104     //@{
00105     double x5[5], w5[5];
00106     double x6[6], w6[6];
00107     //@}
00108 
00109 #endif
00110 
00111   };
00112 
00113 #ifndef DOXYGENP
00114 }
00115 #endif
00116 
00117 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.