I have forgotten

• https://me.yahoo.com
COST (GBP)
5.00
0.00
0

# Brent

viewed 3300 times and licensed 81 times
Calculates the minimum of a one-dimensional real function using Brent's method.
Controller: CodeCogs
Contents

C++

## Brent

 doublebrent( double (*f)(double)[function pointer] double a double b double c double eps = 1E-10 int maxit = 1000 )
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.232938450552

## References:

• GNU Scientific Library, Reference Manual, http://nereida.deioc.ull.es/html/gsl/gsl-ref_24.html

### Parameters

 f the user-defined function a the first point of the bracketing triplet b the second point of the triplet c the third point of the triplet eps Default value = 1E-10 maxit Default value = 1000

### Returns

The approximated abscissa coresponding to the minimum of the function.

### Authors

Lucian Bentea (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.