Class QuadraticRealRootFinder
- java.lang.Object
-
- com.opengamma.strata.math.impl.rootfinding.QuadraticRealRootFinder
-
- All Implemented Interfaces:
Polynomial1DRootFinder<Double>
public class QuadraticRealRootFinder extends Object implements Polynomial1DRootFinder<Double>
Class that calculates the real roots of a quadratic function.The roots can be found analytically. For a quadratic $ax^2 + bx + c = 0$, the roots are given by: $$ \begin{align*} x_{1, 2} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \end{align*} $$ If no real roots exist (i.e. $b^2 - 4ac < 0$) then an exception is thrown.
-
-
Constructor Summary
Constructors Constructor Description QuadraticRealRootFinder()
-
-
-
Method Detail
-
getRoots
public Double[] getRoots(RealPolynomialFunction1D function)
- Specified by:
getRoots
in interfacePolynomial1DRootFinder<Double>
- Parameters:
function
- The function, not null- Returns:
- The roots of the function
- Throws:
IllegalArgumentException
- If the function is not a quadraticMathException
- If the roots are not real
-
-