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=funct,
size_t nsub=100,
class fp_t=
double>
77 #ifndef DOXYGEN_INTERNAL 116 fp_t &res, fp_t &err) {
118 fp_t 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 fp_t bin=(b-a)/((fp_t)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*std::abs(tvals)
189 std::cout <<
"Press a key and type enter to continue. " ;
195 root=sqrt(2.0*terss);
204 if (prev_subdiv==nsub) {
208 std::string s=
"Reached maximum number ("+
itos(nsub)+
209 ") of subdivisions in inte_adapt_cern::integ_err().";
225 fp_t xnew=(xlo[ibig]+xhi[ibig])/2.0;
228 it->
integ_err(func,xlo[ibig],xhi[ibig],tval[ibig],te);
231 xhi[prev_subdiv],tval[prev_subdiv],te);
277 fp_t &value, fp_t &errsq) {
288 template<
class vec_t>
304 #ifndef DOXYGEN_NO_O2NS fp_t tol_abs
The maximum absolute uncertainty in the value of the integral (default )
int get_ith_subdivision(size_t i, fp_t &xlow, fp_t &xhigh, fp_t &value, fp_t &errsq)
Return the ith subdivision.
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.
int prev_subdiv
Previous number of subdivisions.
fp_t tol_rel
The maximum relative uncertainty in the value of the integral (default )
size_t get_nsubdivisions()
Return the number of subdivisions used in the last integration.
fp_t tval[nsub]
Value of integral for subdivision.
virtual int integ_err(func_t &func, fp_t a, fp_t b, fp_t &res, fp_t &err)=0
Integrate function func from a to b and place the result in res and the error in err.
Adaptive integration (CERNLIB)
table table limit exceeded
int set_inte(inte< func_t, fp_t > &i)
Set the base integration object to use.
bool err_nonconv
If true, call the error handler if the routine does not converge or reach the desired tolerance (defa...
inte_gauss56_cern< func_t, fp_t > def_inte
Default integration object.
int get_subdivisions(vec_t &xlow, vec_t &xhigh, vec_t &value, vec_t &errsq)
Return all of the subdivisions.
One-dimensional solver [abstract base].
size_t last_iter
The most recent number of iterations taken.
Base integration class [abstract base].
fp_t ters[nsub]
Squared error for subdivision.
fp_t xlo[nsub]
Lower end of subdivision.
inte< func_t, fp_t > * it
The base integration object.
fp_t xhi[nsub]
High end of subdivision.
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::string itos(int x)
Convert an integer to a string.
size_t nsubdiv
Number of subdivisions.