Package org.ddogleg.solver
Class PolynomialSolver
java.lang.Object
org.ddogleg.solver.PolynomialSolver
Provides functions for finding the roots of polynomials
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic PolynomialRoots
createRootFinder
(RootFinderType type, int maxDegree) Creates a generic polynomial root finding class which will return all real or all real and complex roots depending on the algorithm selected.static double
cubicDiscriminant
(double a, double b, double c, double d) The cubic discriminant is used to determine the type of roots.static double
cubicRootReal
(double a, double b, double c, double d) A cubic polynomial of the form "f(x) = a + b*x + c*x2 + d*x3" has three roots.static Complex_F64[]
polynomialRootsEVD
(double... coefficients) Finds real and imaginary roots in a polynomial using the companion matrix and Eigenvalue decomposition.
-
Constructor Details
-
PolynomialSolver
public PolynomialSolver()
-
-
Method Details
-
createRootFinder
Creates a generic polynomial root finding class which will return all real or all real and complex roots depending on the algorithm selected.- Parameters:
type
- Which algorithm is to be returned.maxDegree
- Maximum degree of the polynomial being considered.- Returns:
- Root finding algorithm.
-
polynomialRootsEVD
Finds real and imaginary roots in a polynomial using the companion matrix and Eigenvalue decomposition. The coefficients order is specified from smallest to largest. Example, 5 + 6*x + 7*x^2 + 8*x^3 = [5,6,7,8]- Parameters:
coefficients
- Polynomial coefficients from smallest to largest.- Returns:
- The found roots.
-
cubicRootReal
public static double cubicRootReal(double a, double b, double c, double d) A cubic polynomial of the form "f(x) = a + b*x + c*x2 + d*x3" has three roots. These roots will either be all real or one real and two imaginary. This function will return a root which is always real.
WARNING: Not as numerically stable as
polynomialRootsEVD(double...)
, but still fairly stable.- Parameters:
a
- polynomial coefficient.b
- polynomial coefficient.c
- polynomial coefficient.d
- polynomial coefficient.- Returns:
- A real root of the cubic polynomial
-
cubicDiscriminant
public static double cubicDiscriminant(double a, double b, double c, double d) The cubic discriminant is used to determine the type of roots.
- if d
>
0, then three distinct real roots - if d = 0, then it has a multiple root and all will be real
- if d
<
0, then one real and two non-real complex conjugate roots
From http://en.wikipedia.org/wiki/Cubic_function November 17, 2011
- Parameters:
a
- polynomial coefficient.b
- polynomial coefficient.c
- polynomial coefficient.d
- polynomial coefficient.- Returns:
- Cubic discriminant
- if d
-