Package dev.nm.analysis.root.univariate
Class BisectionRoot
- java.lang.Object
-
- dev.nm.analysis.root.univariate.BisectionRoot
-
- All Implemented Interfaces:
Uniroot
public class BisectionRoot extends Object implements Uniroot
The bisection method repeatedly bisects an interval and then selects a subinterval in which a root must lie for further processing. It is a very simple and robust method, but it is also relatively slow. The method is guaranteed to converge to a root of f(x) if it is a continuous function on the interval [a, b] and f(a) and f(b) have opposite signs. The absolute error is halved at each step so the method converges linearly.- See Also:
- Wikipedia: Bisection method
-
-
Constructor Summary
Constructors Constructor Description BisectionRoot()Construct an instance withConstants.EPSILONas the tolerance andInteger.MAX_VALUEas the maximum number of iterations.BisectionRoot(double tol, int maxIterations)Construct an instance with the tolerance for convergence and the maximum number of iterations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublesolve(UnivariateRealFunction f, double lower, double upper, double... guess)Search for a root, x, in the interval [lower, upper] such that f(x) = 0.
-
-
-
Constructor Detail
-
BisectionRoot
public BisectionRoot()
Construct an instance withConstants.EPSILONas the tolerance andInteger.MAX_VALUEas the maximum number of iterations.
-
BisectionRoot
public BisectionRoot(double tol, int maxIterations)Construct an instance with the tolerance for convergence and the maximum number of iterations.- Parameters:
tol- the tolerancemaxIterations- the maximum number of iterations
-
-
Method Detail
-
solve
public double solve(UnivariateRealFunction f, double lower, double upper, double... guess) throws NoRootFoundException
Description copied from interface:UnirootSearch for a root, x, in the interval [lower, upper] such that f(x) = 0.- Specified by:
solvein interfaceUniroot- Parameters:
f- a univariate functionlower- the lower bound of the bracketing intervalupper- the upper bound of the bracketing intervalguess- an initial guess of the root within [lower, upper]. Note thatguessis adouble[]. This signature allows multiple initial guesses for certain types of uniroot algorithms, e.g., Brent's algorithm.- Returns:
- an approximate root
- Throws:
NoRootFoundException- when the search fails to find a root
-
-