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 102 virtual const char *
type() {
return "root_brent_gsl"; }
114 if ((fb < 0 && fc < 0) || (fb > 0 && fc > 0)) {
122 if (fabs(fc) < fabs(fb)) {
132 tol=0.5*fabs(b)*std::numeric_limits<double>::epsilon();
142 if (fabs(m) <= tol) {
156 if (fabs(e) < tol || fabs(fa) <= fabs(fb)) {
172 p=s*(2*m*q*(q-r)-(b-a)*(r-1));
182 if (3*m*q-fabs(tol*q)<fabs(e*q)) dtmp=3*m*q-fabs(tol*q);
200 b+=(m > 0 ? +tol : -tol);
210 if ((fb < 0 && fc < 0) || (fb > 0 && fc > 0)) {
229 if (
set(f,x1,x2)!=0) {
252 "root_brent_gsl (abs)");
272 "root_brent_gsl (rel)");
294 "root_brent_gsl (rel)");
300 "root_brent_gsl (abs)");
338 int set(func_t &ff,
double lower,
double upper) {
348 root=0.5*(lower+upper);
350 double f_lower, f_upper;
367 if ((f_lower<0.0 && f_upper<0.0) ||
368 (f_lower>0.0 && f_upper>0.0)) {
369 O2SCL_ERR2(
"Endpoints don't straddle y=0 in ",
377 #ifndef DOXYGEN_INTERNAL 390 double a, b, c, d, e;
398 #ifndef DOXYGEN_NO_O2NS double get_lower()
Get the lower limit.
int ntrial
Maximum number of iterations (default 100)
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
double x_upper
The present upper limit.
double tol_abs
The minimum allowable stepsize (default )
invalid argument supplied by user
exceeded max number of iterations
#define O2SCL_CONV2_RET(d, d2, n, b)
Set an error and return the error value, two-string version.
double root
The present solution estimate.
iteration has not converged
double get_upper()
Get the upper limit.
double get_root()
Get the most recent value of the root.
One-dimensional bracketing solver [abstract base].
double tol_rel
The maximum value of the functions for success (default )
bool err_nonconv
If true, call the error handler if the solver does not converge (default true)
virtual const char * type()
Return the type, "root_brent_gsl".
One-dimensional solver [abstract base].
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 iterate(func_t &f)
Perform an iteration.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
virtual int solve_bkt(double &x1, double x2, func_t &f)
Solve func in region returning .
int test_form
The type of convergence test applied: 0, 1, or 2 (default 0)
One-dimensional root-finding (GSL)
double x_lower
The present lower limit.
static const double x2[5]
static const double x1[5]
int verbose
Output control (default 0)