Go to the documentation of this file.
42 #ifndef O2SCL_MIN_BRENT_GSL_H
43 #define O2SCL_MIN_BRENT_GSL_H
51 #include <gsl/gsl_min.h>
53 #include <o2scl/min.h>
56 #ifndef DOXYGEN_NO_O2NS
98 #ifndef DOXYGEN_INTERNAL
107 double d, e, v, w, f_v, f_w;
112 double xlower,
double *flower,
double xupper,
115 *flower=func(xlower);
116 *fupper=func(xupper);
117 *fminimum=func(xminimum);
145 int set(func_t &func,
double xmin,
double lower,
double upper) {
159 double lower,
double fl,
double upper,
163 std::string tmp=((std::string)
"Invalid interval (lower > upper) ")+
164 "in min_brent_gsl::set_with_values().";
167 if (xmin>=upper || xmin<=lower) {
168 std::string tmp=((std::string)
"'xmin' was not inside interval ")+
169 "in min_brent_gsl::set_with_values().";
172 if (fmin>=fl || fmin>=fu) {
173 std::string tmp=((std::string)
"Endpoints don't enclose minimum ")+
174 "in min_brent_gsl::set_with_values().";
188 const double golden=0.3819660;
216 const double golden=0.3819660;
218 const double w_lower=(z-x_left);
219 const double w_upper=(x_right-z);
221 double sqrt_dbl_eps=sqrt(std::numeric_limits<double>::epsilon());
223 const double tolerance=sqrt_dbl_eps*fabs(z);
225 double p=0, q=0, r=0;
227 const double midpoint=0.5*(x_left+x_right);
229 if (fabs (e) > tolerance) {
247 if (fabs (p) < fabs (0.5*q*r) && p < q*w_lower &&
250 double t2=2*tolerance;
255 if ((u-x_left) < t2 || (x_right-u) < t2) {
256 d=(z < midpoint) ? tolerance : -tolerance ;
261 e=(z < midpoint) ? x_right-z : -(z-x_left) ;
267 if (fabs (d) >= tolerance) {
270 u=z+((d > 0) ? tolerance : -tolerance);
312 if (f_u<=f_w || w==z) {
320 }
else if (f_u<=f_v || v==z || v==w) {
350 "min_brent_gsl::min_bkt().",rx);
371 std::string s=
"Function gsl_min_test_interval() failed in ";
372 s+=
"min_brent_gsl::min_bkt().";
389 this->
tol_abs,
"min_brent_gsl");
395 if (iter>=this->ntrial) {
397 "iterations in min_brent_gsl::min_bkt().",
408 virtual const char *
type() {
return "min_brent_gsl"; }
412 #ifndef DOXYGEN_NO_O2NS
int set_with_values(func_t &func, double xmin, double fmin, double lower, double fl, double upper, double fu)
Set the function, the initial bracketing interval, and the corresponding function values.
double x_minimum
Location of minimum.
virtual const char * type()
Return string denoting type ("min_brent_gsl")
#define O2SCL_CONV2_RET(d, d2, n, b)
Set an error and return the error value, two-string version.
double tol_abs
The tolerance for the location of the minimum.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
double f_minimum
Minimum value.
int iterate()
Perform an iteration.
int ntrial
Maximum number of iterations.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual int min_bkt(double &x2, double x1, double x3, double &fmin, func_t &func)
Calculate the minimum fmin of func with x2 bracketed between x1 and x3.
@ exc_emaxiter
exceeded max number of iterations
int set(func_t &func, double xmin, double lower, double upper)
Set the function and the initial bracketing interval.
double f_upper
Value at upper bound.
static const double x2[5]
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 last_ntrial
The number of iterations used in the most recent minimization.
static const double x1[5]
double f_lower
Value at lower bound.
@ exc_einval
invalid argument supplied by user
double x_upper
Upper bound.
One-dimensional bracketing minimization [abstract base].
@ gsl_continue
iteration has not converged
double x_lower
Lower bound.
int compute_f_values(func_t &func, double xminimum, double *fminimum, double xlower, double *flower, double xupper, double *fupper)
Compute the function values at the various points.
double tol_rel
The tolerance for the minimum function value.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
One-dimensional minimization using Brent's method (GSL)
bool err_nonconv
If true, call the error handler if the routine does not "converge".
int verbose
Output control.
static const double x3[11]
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).