Top Description Fields Constructors Methods
org.apache.commons.math3.analysis.solvers

public Class BrentSolver

extends AbstractUnivariateSolver
Class Inheritance
Imports
org.apache.commons.math3.exception.NoBracketingException, .NumberIsTooLargeException, .TooManyEvaluationsException, org.apache.commons.math3.util.FastMath, .Precision

This class implements the Brent algorithm for finding zeros of real univariate functions. The function should be continuous but not necessarily smooth. The solve method returns a zero x of the function f in the given interval [a, b] to within a tolerance 2 eps abs(x) + t where eps is the relative accuracy and t is the absolute accuracy.

The given interval must bracket the root.

The reference implementation is given in chapter 4 of

Algorithms for Minimization Without Derivatives, Richard P. Brent, Dover, 2002
See Also
BaseAbstractUnivariateSolver

Field Summary

Modifier and TypeField and Description
private static final double
DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

Constructor Summary

AccessConstructor and Description
public
BrentSolver()

Construct a solver with default absolute accuracy (1e-6).

public
BrentSolver(double
Absolute accuracy.
absoluteAccuracy
)

Construct a solver.

public
BrentSolver(double
Relative accuracy.
relativeAccuracy
,
double
Absolute accuracy.
absoluteAccuracy
)

Construct a solver.

public
BrentSolver(double
Relative accuracy.
relativeAccuracy
,
double
Absolute accuracy.
absoluteAccuracy
,
double
Function value accuracy.
functionValueAccuracy
)

Construct a solver.

Method Summary

Modifier and TypeMethod and Description
private double

Returns:

the value where the function is zero.
brent
(double
Lower bound of the search interval.
lo
,
double
Higher bound of the search interval.
hi
,
double
Function value at the lower bound of the search interval.
fLo
,
double
Function value at the higher bound of the search interval.
fHi
)

Search for a zero inside the provided interval.</it>

protected double
doSolve()

Implements abstract org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Method for implementing actual optimization algorithms in derived classes.

Field Detail

DEFAULT_ABSOLUTE_ACCURACYback to summary
private static final double DEFAULT_ABSOLUTE_ACCURACY

Default absolute accuracy.

Constructor Detail

BrentSolverback to summary
public BrentSolver()

Construct a solver with default absolute accuracy (1e-6).

BrentSolverback to summary
public BrentSolver(double absoluteAccuracy)

Construct a solver.

Parameters
absoluteAccuracy:double

Absolute accuracy.

BrentSolverback to summary
public BrentSolver(double relativeAccuracy, double absoluteAccuracy)

Construct a solver.

Parameters
relativeAccuracy:double

Relative accuracy.

absoluteAccuracy:double

Absolute accuracy.

BrentSolverback to summary
public BrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy)

Construct a solver.

Parameters
relativeAccuracy:double

Relative accuracy.

absoluteAccuracy:double

Absolute accuracy.

functionValueAccuracy:double

Function value accuracy.

See Also
BaseAbstractUnivariateSolver#BaseAbstractUnivariateSolver(double, double, double)

Method Detail

brentback to summary
private double brent(double lo, double hi, double fLo, double fHi)

Search for a zero inside the provided interval. This implementation is based on the algorithm described at page 58 of the book

Algorithms for Minimization Without Derivatives, Richard P. Brent, Dover 0-486-41998-3
Parameters
lo:double

Lower bound of the search interval.

hi:double

Higher bound of the search interval.

fLo:double

Function value at the lower bound of the search interval.

fHi:double

Function value at the higher bound of the search interval.

Returns:double

the value where the function is zero.

doSolveback to summary
protected double doSolve() throws NoBracketingException, TooManyEvaluationsException, NumberIsTooLargeException

Implements abstract org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Doc from org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver.doSolve.

Method for implementing actual optimization algorithms in derived classes.

Returns:double

the root.

Annotations
@Override
Exceptions
NoBracketingException:
if the initial search interval does not bracket a root and the solver requires it.
TooManyEvaluationsException:
if the maximal number of evaluations is exceeded.