Class PolynomialSolver

java.lang.Object
org.ddogleg.solver.PolynomialSolver

public class PolynomialSolver extends Object
Provides functions for finding the roots of polynomials
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.

    Methods inherited from class java.lang.Object

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

    • PolynomialSolver

      public PolynomialSolver()
  • Method Details

    • createRootFinder

      public static 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.
      Parameters:
      type - Which algorithm is to be returned.
      maxDegree - Maximum degree of the polynomial being considered.
      Returns:
      Root finding algorithm.
    • polynomialRootsEVD

      public static Complex_F64[] polynomialRootsEVD(double... coefficients)
      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