inte_gsl.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2017, 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 /*
24  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 3 of the License, or (at
29  * your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful, but
32  * WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34  * General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License
37  * along with this program; if not, write to the Free Software
38  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39  * 02110-1301, USA.
40  */
41 #ifndef O2SCL_INTE_GSL_H
42 #define O2SCL_INTE_GSL_H
43 
44 /** \file inte_gsl.h
45  \brief File defining \ref o2scl::inte_gsl
46 */
47 
48 #include <limits>
49 
50 #include <gsl/gsl_machine.h>
51 
52 #ifndef DOXYGEN_NO_O2NS
53 namespace o2scl {
54 #endif
55 
56  /** \brief GSL integration base
57 
58  This base class does not perform any actual integration, but
59  just provides functions to be used in the integration
60  classes based on GSL.
61  */
62  class inte_gsl {
63 
64  public:
65 
66  inte_gsl() {
67  }
68 
69  protected:
70 
71  /** \brief QUADPACK's nonlinear rescaling of the absolute-error
72  estimate.
73 
74  The values \f$ \rho_{\mathrm{abs}} \f$ (stored in
75  <tt>result_abs</tt>) and \f$ \rho_{\mathrm{abs}} \f$ (stored
76  in <tt>result_asc</tt>) are assumed to be
77  \f{eqnarray*}{
78  \rho_{\mathrm{abs}} &=& \int_a^b |f|\,dx, \\
79  \rho_{\mathrm{asc}} &=& \int_a^b |f - \mu(f)|\, dx, \qquad
80  \mu(f) = \frac{1}{b-a}\int_a^b f\, dx,
81  \f}
82  all of which are computed from the best (i.e., finest-grid)
83  approximation of the integrals. The rescaled error, \f$
84  \sigma_\mathrm{err}, \f$ is computed from the raw error, \c
85  err, by
86  \f[
87  \sigma_\mathrm{err} =
88  \rho_\mathrm{asc} \cdot
89  \min \left\{1, \;
90  \left(\frac{200 |\mathrm{err}|}{\rho_\mathrm{asc}} \right)^{3/2}
91  \right\},
92  \f]
93  or
94  \f[
95  \sigma_\mathrm{err} =
96  50\cdot \epsilon_\mathrm{mach} \cdot \rho_\mathrm{abs},
97  \f]
98  whichever of the two is greater. The value \f$
99  \epsilon_\mathrm{mach} \f$ denotes "machine epsilon." (In the
100  case that the second value underflows, the first value is
101  automatically accepted.)
102 
103  This function is used in \ref inte_qng_gsl and \ref
104  inte_kronrod_gsl::gauss_kronrod_base().
105  */
106  double rescale_error(double err, const double result_abs,
107  const double result_asc) {
108 
109  err=fabs(err);
110 
111  if (result_asc != 0 && err != 0) {
112 
113  double scale=pow((200*err/result_asc),1.5);
114 
115  if (scale < 1) {
116  err=result_asc*scale;
117  } else {
118  err=result_asc;
119  }
120  }
121 
122  double dbl_eps=std::numeric_limits<double>::epsilon();
123  double dbl_min=std::numeric_limits<double>::min();
124  //double dbl_eps=GSL_DBL_EPSILON;
125  //double dbl_min=GSL_DBL_MIN;
126 
127  if (result_abs > dbl_min/(50*dbl_eps)) {
128 
129  double min_err=50*dbl_eps*result_abs;
130 
131  if (min_err > err) {
132  err=min_err;
133  }
134  }
135 
136  return err;
137  }
138 
139  };
140 
141 
142 #ifndef DOXYGEN_NO_O2NS
143 }
144 #endif
145 
146 #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
double rescale_error(double err, const double result_abs, const double result_asc)
QUADPACK&#39;s nonlinear rescaling of the absolute-error estimate.
Definition: inte_gsl.h:106
GSL integration base.
Definition: inte_gsl.h:62

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