00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 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 */ 00041 template<class param_t, class func_t> class cern_gauss56 : 00042 public inte<param_t,func_t> { 00043 00044 public: 00045 00046 cern_gauss56() { 00047 x5[0]=4.6910077030668004e-02; 00048 w5[0]=1.1846344252809454e-01; 00049 x5[1]=2.3076534494715846e-01; 00050 w5[1]=2.3931433524968324e-01; 00051 x5[2]=5.0000000000000000e-01; 00052 w5[2]=2.8444444444444444e-01; 00053 x5[3]=7.6923465505284154e-01; 00054 w5[3]=2.3931433524968324e-01; 00055 x5[4]=9.5308992296933200e-01; 00056 w5[4]=1.1846344252809454e-01; 00057 00058 x6[0]=3.3765242898423989e-02; 00059 w6[0]=8.5662246189585178e-02; 00060 x6[1]=1.6939530676686775e-01; 00061 w6[1]=1.8038078652406930e-01; 00062 x6[2]=3.8069040695840155e-01; 00063 w6[2]=2.3395696728634552e-01; 00064 x6[3]=6.1930959304159845e-01; 00065 w6[3]=2.3395696728634552e-01; 00066 x6[4]=8.3060469323313225e-01; 00067 w6[4]=1.8038078652406930e-01; 00068 x6[5]=9.6623475710157601e-01; 00069 w6[5]=8.5662246189585178e-02; 00070 } 00071 00072 /** \brief Integrate function \c func from \c a to \c b. 00073 */ 00074 virtual double integ(func_t &func, double a, double b, param_t &pa) { 00075 double res, err; 00076 integ_err(func,a,b,pa,res,err); 00077 return res; 00078 } 00079 00080 /** 00081 \brief Integrate function \c func from \c a to \c b 00082 giving result \c res and error \c err 00083 */ 00084 virtual int integ_err(func_t &func, double a, double b, param_t &pa, 00085 double &res, double &err) { 00086 00087 double rang=b-a, e5=0.0, e6=0.0, ytmp; 00088 00089 for(int i=0;i<5;i++) { 00090 func(a+rang*x5[i],ytmp,pa); 00091 e5+=w5[i]*ytmp; 00092 func(a+rang*x6[i],ytmp,pa); 00093 e6+=w6[i]*ytmp; 00094 } 00095 func(a+rang*x6[5],ytmp,pa); 00096 e6+=w6[5]*ytmp; 00097 res=(e6+e5)*rang/2.0; 00098 err=fabs((e6-e5)*rang); 00099 00100 return 0; 00101 } 00102 00103 protected: 00104 00105 #ifndef DOXYGEN_INTERNAL 00106 00107 /** \name Integration constants 00108 */ 00109 //@{ 00110 double x5[5], w5[5]; 00111 double x6[6], w6[6]; 00112 //@} 00113 00114 #endif 00115 00116 }; 00117 00118 #ifndef DOXYGENP 00119 } 00120 #endif 00121 00122 #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