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 74 template<
class func_t=funct11,
size_t nsub=100>
77 #ifndef DOXYGEN_INTERNAL 116 double &res,
double &err) {
118 double tvals=0.0, terss, xlob, xhib, yhib=0.0, te,
root=0.0;
122 if (prev_subdiv==0) {
131 it->
integ_err(func,xlo[i],xhi[i],tval[i],te);
151 double bin=(b-a)/((
double)nsubdivd);
152 for(i=0;i<nsubdivd;i++) {
156 if (i==nsubdivd-1) xhi[i]=b;
158 it->
integ_err(func,xlob,xhib,tval[i],te);
161 prev_subdiv=nsubdivd;
163 for(
size_t iter=1;iter<=nsub;iter++) {
176 std::cout <<
"inte_adapt_cern Iter: " << iter;
177 std::cout.setf(std::ios::showpos);
178 std::cout <<
" Res: " << tvals;
179 std::cout.unsetf(std::ios::showpos);
180 std::cout <<
" Err: " << sqrt(2.0*terss);
182 std::cout <<
" Tol: " << this->
tol_abs << std::endl;
184 std::cout <<
" Tol: " << this->
tol_rel*fabs(tvals) << std::endl;
188 std::cout <<
"Press a key and type enter to continue. " ;
194 root=sqrt(2.0*terss);
203 if (prev_subdiv==nsub) {
207 std::string s=
"Reached maximum number ("+
itos(nsub)+
208 ") of subdivisions in inte_adapt_cern::integ_err().";
224 double xnew=(xlo[ibig]+xhi[ibig])/2.0;
227 it->
integ_err(func,xlo[ibig],xhi[ibig],tval[ibig],te);
230 xhi[prev_subdiv],tval[prev_subdiv],te);
276 double &value,
double &errsq) {
287 template<
class vec_t>
303 #ifndef DOXYGEN_NO_O2NS inte_gauss56_cern< func_t > def_inte
Default integration object.
int prev_subdiv
Previous number of subdivisions.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
#define O2SCL_CONV_RET(d, n, b)
Set a "convergence" error and return the error value.
virtual int integ_err(func_t &func, double a, double b, double &res, double &err)=0
Integrate function func from a to b and place the result in res and the error in err.
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.