Go to the documentation of this file.
44 #ifndef O2SCL_ROOT_BRENT_GSL_H
45 #define O2SCL_ROOT_BRENT_GSL_H
52 #include <gsl/gsl_math.h>
53 #include <gsl/gsl_roots.h>
54 #include <o2scl/funct.h>
55 #include <o2scl/root.h>
57 #ifndef DOXYGEN_NO_O2NS
93 public root_bkt<func_t,func_t,fp_t> {
102 fp_t abs_lower, abs_upper;
104 if (xx_lower<0.0) abs_lower=-xx_lower;
105 else abs_lower=xx_lower;
106 if (xx_upper<0.0) abs_upper=-xx_upper;
107 else abs_upper=xx_upper;
109 fp_t min_abs, tolerance;
111 O2SCL_ERR2(
"Relative tolerance is negative in ",
115 O2SCL_ERR2(
"Absolute tolerance is negative in ",
118 if (xx_lower>xx_upper) {
119 O2SCL_ERR2(
"Lower bound larger than upper bound in ",
123 if ((xx_lower>0.0 && xx_upper>0.0) ||
124 (xx_lower<0.0 && xx_upper<0.0)) {
125 if (abs_lower<abs_upper) min_abs=abs_lower;
126 else min_abs=abs_upper;
131 tolerance=epsabs+epsrel*min_abs;
137 if (xx_lower<xx_upper) {
138 if (xx_upper-xx_lower<tolerance) {
142 if (xx_lower-xx_upper<tolerance) {
157 virtual const char *
type() {
return "root_brent_gsl"; }
169 if ((fb < 0 && fc < 0) || (fb > 0 && fc > 0)) {
187 tol=
o2scl::o2abs(b)*std::numeric_limits<fp_t>::epsilon()/two;
227 p=s*(2*m*q*(q-r)-(b-a)*(r-1));
255 b+=(m > 0 ? +tol : -tol);
265 if ((fb < 0 && fc < 0) || (fb > 0 && fc > 0)) {
285 if (set_ret!=0)
return set_ret;
305 this->
tol_abs,
"root_brent_gsl (abs)");
325 "root_brent_gsl (rel)");
347 "root_brent_gsl (rel)");
353 this->
tol_abs,
"root_brent_gsl (abs)");
391 int set(func_t &ff, fp_t lower, fp_t upper) {
402 root=(lower+upper)/two;
404 fp_t f_lower, f_upper;
421 if ((f_lower<0.0 && f_upper<0.0) ||
422 (f_lower>0.0 && f_upper>0.0)) {
432 #ifndef DOXYGEN_INTERNAL
453 #ifndef DOXYGEN_NO_O2NS
double tol_rel
The maximum value of the functions for success (default )
#define O2SCL_CONV2_RET(d, d2, n, b)
Set an error and return the error value, two-string version.
fp_t get_upper()
Get the upper limit.
fp_t x_lower
The present lower limit.
double tol_abs
The minimum allowable stepsize (default )
One-dimensional bracketing solver [abstract base].
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual int solve_bkt(fp_t &x1, fp_t x2, func_t &f)
Solve func in region returning .
@ exc_emaxiter
exceeded max number of iterations
virtual int print_iter(double x, double y, int iter, double value=0.0, double limit=0.0, std::string comment="")
Print out iteration information.
int verbose
Output control (default 0)
One-dimensional solver [abstract base].
virtual const char * type()
Return the type, "root_brent_gsl".
static const double x2[5]
static const double x1[5]
One-dimensional root-finding (GSL)
@ exc_einval
invalid argument supplied by user
fp_t x_upper
The present upper limit.
@ gsl_continue
iteration has not converged
int test_form
The type of convergence test applied: 0, 1, or 2 (default 0)
int iterate(func_t &f)
Perform an iteration.
int test_interval(fp_t xx_lower, fp_t xx_upper, fp_t epsabs, fp_t epsrel)
Floating point-type agnostic version of gsl_root_test_interval() .
fp_t get_root()
Get the most recent value of the root.
float o2abs(const float x)
Absolute value for single precision numbers.
fp_t root
The present solution estimate.
bool err_nonconv
If true, call the error handler if the solver does not converge (default true)
@ exc_ebadtol
user specified an invalid tolerance
int ntrial
Maximum number of iterations (default 100)
int set(func_t &ff, fp_t lower, fp_t upper)
Set the information for the solver.
fp_t get_lower()
Get the lower limit.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).