Click or drag to resize
Accord.NET (logo)

BrentSearch Class

Brent's root finding and minimization algorithms.
Inheritance Hierarchy
SystemObject
  Accord.Math.OptimizationBrentSearch

Namespace:  Accord.Math.Optimization
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public sealed class BrentSearch : IOptimizationMethod<double, double>
Request Example View Source

The BrentSearch type exposes the following members.

Constructors
  NameDescription
Public methodBrentSearch
Constructs a new Brent search algorithm.
Top
Properties
  NameDescription
Public propertyFunction
Gets the function to be searched.
Public propertyLowerBound
Gets or sets the lower bound for the search interval a.
Public propertyMaxIterations
Gets or sets the maximum number of iterations that should be performed before the method terminates. Default is 500.
Public propertyNumberOfVariables
Gets the number of variables (free parameters) in the optimization problem.
Public propertySolution
Public propertyStatus
Gets the status of the search.
Public propertyTolerance
Gets or sets the tolerance margin when looking for an answer. Default is 1e-6.
Public propertyUpperBound
Gets or sets the lower bound for the search interval a.
Public propertyValue
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodFind(Double)
Attempts to find a value in the interval [a;b]
Public methodStatic memberFind(FuncDouble, Double, Double, Double, Double, Double, Int32)
Finds a value of a function in the interval [a;b]
Public methodFindRoot
Attempts to find a root in the interval [a;b]
Public methodStatic memberFindRoot(FuncDouble, Double, Double, Double, Double, Int32)
Finds the root of a function in the interval [a;b]
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodMaximize
Finds the maximum of the function in the interval [a;b]
Public methodStatic memberMaximize(FuncDouble, Double, Double, Double, Double, Int32)
Finds the maximum of a function in the interval [a;b]
Public methodMinimize
Finds the minimum of the function in the interval [a;b]
Public methodStatic memberMinimize(FuncDouble, Double, Double, Double, Double, Int32)
Finds the minimum of a function in the interval [a;b]
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

In numerical analysis, Brent's method is a complicated but popular root-finding algorithm combining the bisection method, the secant method and inverse quadratic interpolation. It has the reliability of bisection but it can be as quick as some of the less reliable methods. The idea is to use the secant method or inverse quadratic interpolation if possible, because they converge faster, but to fall back to the more robust bisection method if necessary. Brent's method is due to Richard Brent (1973) and builds on an earlier algorithm of Theodorus Dekker (1969).

The algorithms implemented in this class are based on the original C source code available in Netlib (http://www.netlib.org/c/brent.shar) by Oleg Keselyov, 1991.

References:

Examples

The following example shows how to compute the maximum, minimum and a single root of a univariate function.

// Suppose we were given the function x³ + 2x² - 10x + 1 and 
// we have to find its root, maximum and minimum inside 
// the interval [-4, 2]. First, we express this function
// as a lambda expression:
Func<double, double> function = x => x * x * x + 2 * x * x - 10 * x + 1;

// And now we can create the search algorithm:
BrentSearch search = new BrentSearch(function, -4, 2);

// Finally, we can query the information we need
bool success1 = search.Maximize();  // should be true
double max = search.Solution;       // occurs at -2.61

bool success2 = search.Minimize();   // should be true  
double min = search.Solution;       // occurs at  1.28

bool success3 = search.FindRoot();  // should be true 
double root = search.Solution;      // occurs at  0.10
double value = search.Value;        // should be zero
See Also