inte_gauss56_cern.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2018, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 /** \file inte_gauss56_cern.h
24  \brief File defining \ref o2scl::inte_gauss56_cern
25 */
26 #ifndef O2SCL_CERN_GAUSS56_H
27 #define O2SCL_CERN_GAUSS56_H
28 
29 #include <o2scl/inte.h>
30 #include <o2scl/funct.h>
31 
32 #ifndef DOXYGEN_NO_O2NS
33 namespace o2scl {
34 #endif
35 
36  /** \brief Fifth order integration abscissas for
37  \ref o2scl::inte_gauss56_cern in double precision
38  */
39  static const double inte_gauss56_cern_x5_double[5]=
40  {4.6910077030668004e-02,2.3076534494715846e-01,
41  5.0000000000000000e-01,7.6923465505284154e-01,
42  9.5308992296933200e-01};
43 
44  /** \brief Fifth order integration weights for
45  \ref o2scl::inte_gauss56_cern in double precision
46  */
47  static const double inte_gauss56_cern_w5_double[5]=
48  {1.1846344252809454e-01,2.3931433524968324e-01,
49  2.8444444444444444e-01,2.3931433524968324e-01,
50  1.1846344252809454e-01};
51 
52  /** \brief Sixth order integration abscissas for
53  \ref o2scl::inte_gauss56_cern in double precision
54  */
55  static const double inte_gauss56_cern_x6_double[6]=
56  {3.3765242898423989e-02,1.6939530676686775e-01,
57  3.8069040695840155e-01,6.1930959304159845e-01,
58  8.3060469323313225e-01,9.6623475710157601e-01};
59 
60  /** \brief Sixth order integration weights for
61  \ref o2scl::inte_gauss56_cern in double precision
62  */
63  static const double inte_gauss56_cern_w6_double[6]=
64  {8.5662246189585178e-02,1.8038078652406930e-01,
65  2.3395696728634552e-01,2.3395696728634552e-01,
66  1.8038078652406930e-01,8.5662246189585178e-02};
67 
68  /** \brief Fifth order integration abscissas for
69  \ref o2scl::inte_gauss56_cern in long double precision
70  */
71  static const long double inte_gauss56_cern_x5_long_double[5]=
72  {0.04691007703066800360118656085030352L,
73  0.23076534494715845448184278964989560L,
74  0.5L,
75  0.76923465505284154551815721035010440L,
76  0.95308992296933199639881343914969648L};
77 
78  /** \brief Fifth order integration weights for
79  \ref o2scl::inte_gauss56_cern in long double precision
80  */
81  static const long double inte_gauss56_cern_w5_long_double[5]=
82  {0.11846344252809454375713202035995868L,
83  0.23931433524968323402064575741781910L,
84  0.28444444444444444444444444444444444L,
85  0.23931433524968323402064575741781910L,
86  0.11846344252809454375713202035995868L};
87 
88  /** \brief Sixth order integration abscissas for
89  \ref o2scl::inte_gauss56_cern in long double precision
90  */
91  static const long double inte_gauss56_cern_x6_long_double[6]=
92  {0.03376524289842398609384922275300270L,
93  0.16939530676686774316930020249004733L,
94  0.38069040695840154568474913915964403L,
95  0.61930959304159845431525086084035597L,
96  0.83060469323313225683069979750995267L,
97  0.96623475710157601390615077724699730L};
98 
99  /** \brief Sixth order integration weights for
100  \ref o2scl::inte_gauss56_cern in long double precision
101  */
102  static const long double inte_gauss56_cern_w6_long_double[6]=
103  {0.08566224618958517252014807108636645L,
104  0.18038078652406930378491675691885806L,
105  0.23395696728634552369493517199477550L,
106  0.23395696728634552369493517199477550L,
107  0.18038078652406930378491675691885806L,
108  0.08566224618958517252014807108636645L};
109 
110  /** \brief 5,6-point Gaussian quadrature (CERNLIB)
111 
112  If \f$ I_5 \f$ is the 5-point approximation, and \f$ I_6 \f$ is the
113  6-point approximation to the integral, then integ_err() returns
114  the result \f$ \frac{1}{2}(I_5+I_6) \f$ with uncertainty
115  \f$ |I_5-I_6| \f$.
116 
117  This class is based on the CERNLIB routines RGS56P and
118  DGS56P which are documented at
119  http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/d106/top.html
120 
121  \note Currently \o2 supports only types \c double and
122  \c long \c double for the floating point type \c fp_t .
123  */
124  template<class func_t=funct, class fp_t=double,
125  const fp_t x5[]=inte_gauss56_cern_x5_double,
126  const fp_t w5[]=inte_gauss56_cern_w5_double,
127  const fp_t x6[]=inte_gauss56_cern_x6_double,
128  const fp_t w6[]=inte_gauss56_cern_w6_double>
129  class inte_gauss56_cern : public inte<func_t,fp_t> {
130 
131  public:
132 
134  }
135 
136  /** \brief Integrate function \c func from \c a to \c b
137  giving result \c res and error \c err
138 
139  This function always returns \ref success.
140  */
141  virtual int integ_err(func_t &func, fp_t a, fp_t b,
142  fp_t &res, fp_t &err) {
143 
144  fp_t rang=b-a, e5=0.0, e6=0.0, ytmp;
145 
146  for(int i=0;i<5;i++) {
147  ytmp=func(a+rang*x5[i]);
148  e5+=w5[i]*ytmp;
149  ytmp=func(a+rang*x6[i]);
150  e6+=w6[i]*ytmp;
151  }
152  ytmp=func(a+rang*x6[5]);
153  e6+=w6[5]*ytmp;
154  res=(e6+e5)*rang/2.0;
155  err=std::abs((e6-e5)*rang);
156 
157  return success;
158  }
159 
160  };
161 
162 #ifndef DOXYGEN_NO_O2NS
163 }
164 #endif
165 
166 #endif
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
static const long double inte_gauss56_cern_w5_long_double[5]
Fifth order integration weights for o2scl::inte_gauss56_cern in long double precision.
static const double inte_gauss56_cern_w5_double[5]
Fifth order integration weights for o2scl::inte_gauss56_cern in double precision. ...
static const long double inte_gauss56_cern_x6_long_double[6]
Sixth order integration abscissas for o2scl::inte_gauss56_cern in long double precision.
static const long double inte_gauss56_cern_x5_long_double[5]
Fifth order integration abscissas for o2scl::inte_gauss56_cern in long double precision.
Base integration class [abstract base].
Definition: inte.h:51
5,6-point Gaussian quadrature (CERNLIB)
static const long double inte_gauss56_cern_w6_long_double[6]
Sixth order integration weights for o2scl::inte_gauss56_cern in long double precision.
static const double inte_gauss56_cern_w6_double[6]
Sixth order integration weights for o2scl::inte_gauss56_cern in double precision. ...
static const double inte_gauss56_cern_x6_double[6]
Sixth order integration abscissas for o2scl::inte_gauss56_cern in double precision.
virtual int integ_err(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err)
Integrate function func from a to b giving result res and error err.
std::function< double(double)> funct
One-dimensional function typedef.
Definition: funct.h:45
static const double inte_gauss56_cern_x5_double[5]
Fifth order integration abscissas for o2scl::inte_gauss56_cern in double precision.
Success.
Definition: err_hnd.h:47

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