Class BisectionSingleRootFinder
- java.lang.Object
-
- com.opengamma.strata.math.impl.rootfinding.RealSingleRootFinder
-
- com.opengamma.strata.math.impl.rootfinding.BisectionSingleRootFinder
-
- All Implemented Interfaces:
SingleRootFinder<Double,Double>
public class BisectionSingleRootFinder extends RealSingleRootFinder
Finds a single root of a function using the bisection method.If a root of a function $f(x)$ is bounded by two values $x_1$ and $x_2$, then $f(x_1)f(x_2) < 0$. The function is evaluated at the midpoint of these values and the bound that gives the same sign in the function evaluation is replaced. The bisection is stopped when the change in the value of $x$ is below the accuracy, or the evaluation of the function at $x$ is zero.
-
-
Constructor Summary
Constructors Constructor Description BisectionSingleRootFinder()
Creates an instance.BisectionSingleRootFinder(double accuracy)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Double
getRoot(Function<Double,Double> function, Double x1, Double x2)
-
Methods inherited from class com.opengamma.strata.math.impl.rootfinding.RealSingleRootFinder
checkInputs, checkInputs, getRoot
-
-
-
-
Constructor Detail
-
BisectionSingleRootFinder
public BisectionSingleRootFinder()
Creates an instance. Sets the accuracy to 10-15.
-
BisectionSingleRootFinder
public BisectionSingleRootFinder(double accuracy)
Creates an instance.- Parameters:
accuracy
- The required accuracy of the $x$-position of the root
-
-
Method Detail
-
getRoot
public Double getRoot(Function<Double,Double> function, Double x1, Double x2)
- Specified by:
getRoot
in classRealSingleRootFinder
- Throws:
MathException
- If the root is not found to the required accuracy in 100 attempts
-
-