26 #ifndef O2SCL_CERN_ADAPT_H
27 #define O2SCL_CERN_ADAPT_H
29 #include <o2scl/inte.h>
30 #include <o2scl/inte_gauss56_cern.h>
31 #include <o2scl/string_conv.h>
33 #ifndef DOXYGEN_NO_O2NS
73 template<
class func_t=funct11,
size_t nsub=100>
76 #ifndef DOXYGEN_INTERNAL
115 double &res,
double &err) {
117 double tvals=0.0, terss, xlob, xhib, yhib=0.0, te,
root=0.0;
150 double bin=(b-a)/((
double)nsubdivd);
151 for(i=0;i<nsubdivd;i++) {
155 if (i==nsubdivd-1)
xhi[i]=b;
157 it->integ_err(func,xlob,xhib,
tval[i],te);
162 for(
size_t iter=1;iter<=nsub;iter++) {
175 std::cout <<
"inte_adapt_cern Iter: " << iter;
176 std::cout.setf(std::ios::showpos);
177 std::cout <<
" Res: " << tvals;
178 std::cout.unsetf(std::ios::showpos);
179 std::cout <<
" Err: " << sqrt(2.0*terss);
181 std::cout <<
" Tol: " << this->
tol_abs << std::endl;
183 std::cout <<
" Tol: " << this->
tol_rel*fabs(tvals) << std::endl;
187 std::cout <<
"Press a key and type enter to continue. " ;
193 root=sqrt(2.0*terss);
202 if (prev_subdiv==nsub) {
206 std::string s=
"Reached maximum number ("+
itos(nsub)+
207 ") of subdivisions in inte_adapt_cern::integ_err().";
223 double xnew=(
xlo[ibig]+
xhi[ibig])/2.0;
228 it->integ_err(func,
xlo[prev_subdiv],
229 xhi[prev_subdiv],
tval[prev_subdiv],te);
275 double &value,
double &errsq) {
286 template<
class vec_t>
302 #ifndef DOXYGEN_NO_O2NS
inte_gauss56_cern< func_t > def_inte
Default integration object.
int prev_subdiv
Previous number of subdivisions.
#define O2SCL_CONV_RET(d, n, b)
Set a "convergence" error and return the error value.
double xhi[nsub]
High end of subdivision.
virtual int integ_err(func_t &func, double a, double b, double &res, double &err)
Integrate function func from a to b giving result res and error err.
Adaptive integration (CERNLIB)
inte< func_t > * it
The base integration object.
size_t last_iter
The most recent number of iterations taken.
bool err_nonconv
If true, call the error handler if the routine does not converge or reach the desired tolerance (defa...
table table limit exceeded
size_t get_nsubdivisions()
Return the number of subdivisions used in the last integration.
double tol_abs
The maximum absolute uncertainty in the value of the integral (default )
int get_ith_subdivision(size_t i, double &xlow, double &xhigh, double &value, double &errsq)
Return the ith subdivision.
One-dimensional solver [abstract base].
Base integration class [abstract base].
5,6-point Gaussian quadrature (CERNLIB)
int set_inte(inte< func_t > &i)
Set the base integration object to use.
double ters[nsub]
Squared error for subdivision.
double tval[nsub]
Value of integral for subdivision.
size_t nsubdiv
Number of subdivisions.
double xlo[nsub]
Lower end of subdivision.
double tol_rel
The maximum relative uncertainty in the value of the integral (default )
std::string itos(int x)
Convert an integer to a string.
int get_subdivisions(vec_t &xlow, vec_t &xhigh, vec_t &value, vec_t &errsq)
Return all of the subdivisions.