FUNCTION
Brent
Calculates the minimum of a one-dimensional real function using Brent's method.
You're viewing an older version of this page (#87). View the current version.
Interface
#include <codecogs/maths/optimization/brent.h>
using namespace Maths::Optimization;
Given a user-defined function f and a bracketing triplet of abscissas (such that
and
) this routine isolates the minimum to a fractional precision of about eps using Brent's method. Finally it returns the abscissa corresponding to the minimum of the function.
The Brent minimization algorithm combines a parabolic interpolation with the golden section algorithm. This produces a fast algorithm which is still robust.
The outline of the algorithm can be summarized as follows: on each iteration Brent's method approximates the function using an interpolating parabola through three existing points. The minimum of the parabola is taken as a guess for the minimum. If it lies within the bounds of the current interval then the interpolating point is accepted, and used to generate a smaller interval. If the interpolating point is not accepted then the algorithm falls back to an ordinary golden section step. Also included are some additional checks to improve convergence.
Below you will find a diagram of the parabolic interpolation step. The triples at consecutive steps are

Example 1
#include <codecogs/maths/optimization/brent.h>
#include <iostream>
#include <iomanip>
#include <cmath>
// user-defined function
double f(double x) {
return x * sin(x) - 2 * cos(x);
}
int main()
{
double x = Maths::Optimization::brent(f, 4, 5, 6);
std::cout << "Function minimum is Y = " << std::setprecision(13) << f(x);
std::cout << std::endl;
std::cout << "for X = " << x << std::endl;
return 0;
}Output
Function minimum is Y = -5.534528774008
for X = 5.232938450552References
- GNU Scientific Library, Reference Manual, http://nereida.deioc.ull.es/html/gsl/gsl-ref_24.html