maspack.util

• java.lang.Object

• ```public class QuadraticSolver
extends java.lang.Object```
Finds the real roots of a quadratic equation, attempting to handle numerical issues as best as possible.
• ### Constructor Summary

Constructors
Constructor and Description
`QuadraticSolver()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static int` ```getRoots(double[] roots, double a, double b, double c)```
Find the real roots of the quadratic equation
`static int` ```getRoots(double[] roots, double a, double b, double c, double xlo, double xhi)```
Find the real roots of the quadratic equation
• ### Methods inherited from class java.lang.Object

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

`public QuadraticSolver()`
• ### Method Detail

• #### getRoots

```public static int getRoots(double[] roots,
double a,
double b,
double c)```
Find the real roots of the quadratic equation
```    a x^2 + b x + c = 0
```
There will be either 0, 1, or 2 roots, where the single root case occurs when a = 0 or when there is a repeated root. When there are two roots, they are sorted in increasing order.
Parameters:
`roots` - returns the roots, must have length `>=` 2
`a` - first coefficient
`b` - second coefficient
`c` - third coefficient
Returns:
number of roots found
• #### getRoots

```public static int getRoots(double[] roots,
double a,
double b,
double c,
double xlo,
double xhi)```
Find the real roots of the quadratic equation
```    a x^2 + b x + c = 0
```
that lie within the interval [xlo, xhi]. There will be either 0, 1, or 2 roots, where the single root case occurs when a = 0 or when there is a repeated root. When there are two roots, they are sorted in increasing order.
Parameters:
`roots` - returns the roots, must have length `>=` 2
`a` - first coefficient
`b` - second coefficient
`c` - third coefficient
`xlo` - lower bound on x
`xhi` - upper bound on x
Returns:
number of roots found