Class BrentSolver
- java.lang.Object
-
- org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver<UnivariateFunction>
-
- org.apache.commons.math3.analysis.solvers.AbstractUnivariateSolver
-
- org.apache.commons.math3.analysis.solvers.BrentSolver
-
- All Implemented Interfaces:
BaseUnivariateSolver<UnivariateFunction>,UnivariateSolver
public class BrentSolver extends AbstractUnivariateSolver
This class implements the Brent algorithm for finding zeros of real univariate functions. The function should be continuous but not necessarily smooth. Thesolvemethod returns a zeroxof the functionfin the given interval[a, b]to within a tolerance2 eps abs(x) + twhereepsis the relative accuracy andtis 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
Fields Modifier and Type Field Description private static doubleDEFAULT_ABSOLUTE_ACCURACYDefault absolute accuracy.
-
Constructor Summary
Constructors Constructor Description BrentSolver()Construct a solver with default absolute accuracy (1e-6).BrentSolver(double absoluteAccuracy)Construct a solver.BrentSolver(double relativeAccuracy, double absoluteAccuracy)Construct a solver.BrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy)Construct a solver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private doublebrent(double lo, double hi, double fLo, double fHi)Search for a zero inside the provided interval.protected doubledoSolve()Method for implementing actual optimization algorithms in derived classes.-
Methods inherited from class org.apache.commons.math3.analysis.solvers.BaseAbstractUnivariateSolver
computeObjectiveValue, getAbsoluteAccuracy, getEvaluations, getFunctionValueAccuracy, getMax, getMaxEvaluations, getMin, getRelativeAccuracy, getStartValue, incrementEvaluationCount, isBracketing, isSequence, setup, solve, solve, solve, verifyBracketing, verifyInterval, verifySequence
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.math3.analysis.solvers.BaseUnivariateSolver
getAbsoluteAccuracy, getEvaluations, getFunctionValueAccuracy, getMaxEvaluations, getRelativeAccuracy, solve, solve, solve
-
-
-
-
Field Detail
-
DEFAULT_ABSOLUTE_ACCURACY
private static final double DEFAULT_ABSOLUTE_ACCURACY
Default absolute accuracy.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrentSolver
public BrentSolver()
Construct a solver with default absolute accuracy (1e-6).
-
BrentSolver
public BrentSolver(double absoluteAccuracy)
Construct a solver.- Parameters:
absoluteAccuracy- Absolute accuracy.
-
BrentSolver
public BrentSolver(double relativeAccuracy, double absoluteAccuracy)Construct a solver.- Parameters:
relativeAccuracy- Relative accuracy.absoluteAccuracy- Absolute accuracy.
-
BrentSolver
public BrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy)Construct a solver.- Parameters:
relativeAccuracy- Relative accuracy.absoluteAccuracy- Absolute accuracy.functionValueAccuracy- Function value accuracy.- See Also:
BaseAbstractUnivariateSolver(double,double,double)
-
-
Method Detail
-
doSolve
protected double doSolve() throws NoBracketingException, TooManyEvaluationsException, NumberIsTooLargeExceptionMethod for implementing actual optimization algorithms in derived classes.- Specified by:
doSolvein classBaseAbstractUnivariateSolver<UnivariateFunction>- Returns:
- the root.
- Throws:
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.NumberIsTooLargeException
-
brent
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 bookAlgorithms for Minimization Without Derivatives,
Richard P. Brent , Dover 0-486-41998-3- Parameters:
lo- Lower bound of the search interval.hi- Higher bound of the search interval.fLo- Function value at the lower bound of the search interval.fHi- Function value at the higher bound of the search interval.- Returns:
- the value where the function is zero.
-
-