00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 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 /** 00033 \brief 5,6-point Gaussian quadrature (CERNLIB) 00034 00035 If \f$ I_5 \f$ is the 5-point approximation, and \f$ I_6 \f$ is the 00036 6-point approximation to the integral, then integ_err() returns 00037 the result \f$ \frac{1}{2}(I_5+I_6) \f$ with uncertainty 00038 \f$ |I_5-I_6| \f$. 00039 00040 This class is based on the CERNLIB routines RGS56P and 00041 DGS56P which are documented at 00042 http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/d106/top.html 00043 00044 */ 00045 template<class param_t, class func_t> class cern_gauss56 : 00046 public inte<param_t,func_t> { 00047 00048 public: 00049 00050 cern_gauss56() { 00051 x5[0]=4.6910077030668004e-02; 00052 w5[0]=1.1846344252809454e-01; 00053 x5[1]=2.3076534494715846e-01; 00054 w5[1]=2.3931433524968324e-01; 00055 x5[2]=5.0000000000000000e-01; 00056 w5[2]=2.8444444444444444e-01; 00057 x5[3]=7.6923465505284154e-01; 00058 w5[3]=2.3931433524968324e-01; 00059 x5[4]=9.5308992296933200e-01; 00060 w5[4]=1.1846344252809454e-01; 00061 00062 x6[0]=3.3765242898423989e-02; 00063 w6[0]=8.5662246189585178e-02; 00064 x6[1]=1.6939530676686775e-01; 00065 w6[1]=1.8038078652406930e-01; 00066 x6[2]=3.8069040695840155e-01; 00067 w6[2]=2.3395696728634552e-01; 00068 x6[3]=6.1930959304159845e-01; 00069 w6[3]=2.3395696728634552e-01; 00070 x6[4]=8.3060469323313225e-01; 00071 w6[4]=1.8038078652406930e-01; 00072 x6[5]=9.6623475710157601e-01; 00073 w6[5]=8.5662246189585178e-02; 00074 } 00075 00076 /** \brief Integrate function \c func from \c a to \c b. 00077 */ 00078 virtual double integ(func_t &func, double a, double b, param_t &pa) { 00079 double res; 00080 integ_err(func,a,b,pa,res,this->interror); 00081 return res; 00082 } 00083 00084 /** 00085 \brief Integrate function \c func from \c a to \c b 00086 giving result \c res and error \c err 00087 */ 00088 virtual int integ_err(func_t &func, double a, double b, param_t &pa, 00089 double &res, double &err) { 00090 00091 double rang=b-a, e5=0.0, e6=0.0, ytmp; 00092 00093 for(int i=0;i<5;i++) { 00094 func(a+rang*x5[i],ytmp,pa); 00095 e5+=w5[i]*ytmp; 00096 func(a+rang*x6[i],ytmp,pa); 00097 e6+=w6[i]*ytmp; 00098 } 00099 func(a+rang*x6[5],ytmp,pa); 00100 e6+=w6[5]*ytmp; 00101 res=(e6+e5)*rang/2.0; 00102 err=fabs((e6-e5)*rang); 00103 00104 return 0; 00105 } 00106 00107 protected: 00108 00109 #ifndef DOXYGEN_INTERNAL 00110 00111 /** \name Integration constants 00112 */ 00113 //@{ 00114 double x5[5], w5[5]; 00115 double x6[6], w6[6]; 00116 //@} 00117 00118 #endif 00119 00120 }; 00121 00122 #ifndef DOXYGENP 00123 } 00124 #endif 00125 00126 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page