Class BrentSolver
- java.lang.Object
-
- org.apache.commons.numbers.rootfinder.BrentSolver
-
public class BrentSolver extends Object
This class implements the Brent algorithm for finding zeros of real univariate functions. The function should be continuous but not necessarily smooth. Thesolve
method returns a zerox
of the functionf
in the given interval[a, b]
to within a tolerance2 eps abs(x) + t
whereeps
is the relative accuracy andt
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
-
-
Constructor Summary
Constructors Constructor Description BrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy)
Construct a solver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
findRoot(DoubleUnaryOperator func, double min, double max)
Search the function's zero within the given interval.double
findRoot(DoubleUnaryOperator func, double min, double initial, double max)
Search the function's zero within the given interval, starting from the given estimate.
-
-
-
Constructor Detail
-
BrentSolver
public BrentSolver(double relativeAccuracy, double absoluteAccuracy, double functionValueAccuracy)
Construct a solver.- Parameters:
relativeAccuracy
- Relative accuracy.absoluteAccuracy
- Absolute accuracy.functionValueAccuracy
- Function value accuracy.
-
-
Method Detail
-
findRoot
public double findRoot(DoubleUnaryOperator func, double min, double max)
Search the function's zero within the given interval.- Parameters:
func
- Function to solve.min
- Lower bound.max
- Upper bound.- Returns:
- the root.
- Throws:
IllegalArgumentException
- ifmin > max
.IllegalArgumentException
- if the given interval does not bracket the root.
-
findRoot
public double findRoot(DoubleUnaryOperator func, double min, double initial, double max)
Search the function's zero within the given interval, starting from the given estimate.- Parameters:
func
- Function to solve.min
- Lower bound.initial
- Initial guess.max
- Upper bound.- Returns:
- the root.
- Throws:
IllegalArgumentException
- ifmin > max
orinitial
is not in the[min, max]
interval.IllegalArgumentException
- if the given interval does not bracket the root.
-
-