I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 5.00
sub units 0.00
+
0

Brent

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

Interface

C++

Brent

 
doublebrentdouble(*f)(double)[function pointer]
doublea
doubleb
doublec
doubleeps = 1E-10
intmaxit = 1000 )
Given a user-defined function f and a bracketing triplet of abscissas \inline (a, b, c) (such that \inline a < b < c and \inline f(a) > f(b) < f(c)) 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

MISSING IMAGE!

1/brent-378.png cannot be found in /users/1/brent-378.png. Please contact the submission author.

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

fthe user-defined function
athe first point of the bracketing triplet
bthe second point of the triplet
cthe third point of the triplet
epsDefault value = 1E-10
maxitDefault 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.