# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.root.univariate

## Class BisectionRoot

• java.lang.Object
• com.numericalmethod.suanshu.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.

Wikipedia: Bisection method
• ### Constructor Summary

Constructors
Constructor and Description
BisectionRoot()
Create an instance with Constants.EPSILON as the tolerance and Integer.MAX_VALUE as the maximum number of iterations.
BisectionRoot(double tol, int maxIterations)
Create an instance with the tolerance for convergence and the maximum number of iterations.
• ### Method Summary

All Methods
Modifier and Type Method and Description
double solve(UnivariateRealFunction f, double lower, double upper, double... guess)
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### BisectionRoot

public BisectionRoot(double tol,
int maxIterations)
Create an instance with the tolerance for convergence and the maximum number of iterations.
Parameters:
tol - the tolerance
maxIterations - 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: Uniroot
Search for a root, x, in the interval [lower, upper] such that f(x) = 0.
Specified by:
solve in interface Uniroot
Parameters:
f - a univariate function
lower - the lower bound of the bracketing interval
upper - the upper bound of the bracketing interval
guess - an initial guess of the root within [lower, upper]. Note that guess is a double[]. 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