Class SecondDegreePolynomialRootsEstimator


public class SecondDegreePolynomialRootsEstimator extends PolynomialRootsEstimator
Class to estimate the roots of a second degree polynomial along with other polynomial properties. A second degree polynomial is defined by its parameters as p(x) = a * x^2 + b * x + c, hence the polynomial can be simply be defined by an array of length 3 [c, b, a] This class is based on: http://en.wikipedia.org/wiki/Quadratic_function
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Constant defining machine precision.
    private double[]
    Array containing parameters of a second degree polynomial.
    static final int
    Number of parameters valid for a second degree polynomial.

    Fields inherited from class com.irurueta.numerical.roots.PolynomialRootsEstimator

    polyParams, roots

    Fields inherited from class com.irurueta.numerical.roots.RootEstimator

    locked
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns boolean indicating whether REAL polynomial parameters have been provided and is available for retrieval.
    void
    Estimates the roots of provided polynomial.
    private static double
    getDiscriminant(double[] polyParams)
    Internal method to compute the discriminant of a 2nd degree polynomial.
    com.irurueta.algebra.Complex[]
    This method will always raise a NotAvailableException because this class only supports REAL polynomial parameters
    double[]
    Returns array of second degree polynomial parameters.
    boolean
    Returns boolean indicating whether this second degree polynomial has multiple roots (for the 2nd degree case this means 2 equal roots) This is true for polynomials of the form (x - r)^2 = x^2 - 2 * r * x + r^2, where r is the double root
    static boolean
    hasDoubleRoot(double[] polyParams)
    Returns boolean indicating whether a second degree polynomial has multiple roots (for the 2nd degree case this means 2 equal roots) This is true for polynomials of the form (x - r)^2 = x^2 - 2 * r * x + r^2, where r is the double root
    boolean
    Returns boolean indicating whether the roots of the polynomial are two complex conjugate roots or not.
    static boolean
    hasTwoComplexConjugateRoots(double[] polyParams)
    Returns boolean indicating whether the roots of the polynomial are two complex conjugate roots or not.
    boolean
    Returns boolean indicating whether the roots of the polynomial are two distinct and real roots or not.
    boolean
    hasTwoDistinctRealRoots(double[] polyParams)
    Returns boolean indicating whether the roots of the polynomial are two distinct and real roots or not.
    private void
    internalSetPolynomialParameters(double[] polyParams)
    Internal method to set array of second degree polynomial parameters.
    protected void
    internalSetPolynomialParameters(com.irurueta.algebra.Complex[] polyParams)
    This method will always raise an IllegalArgumentException because this class only supports REAL polynomial parameters
    boolean
    Returns boolean indicating whether polynomial parameters provided to this instance correspond to a valid second degree polynomial.
    static boolean
    isSecondDegree(double[] polyParams)
    Returns boolean indicating whether provided array of polynomial parameters correspond to a valid second degree polynomial.
    void
    setPolynomialParameters(double[] polyParams)
    Set array of second degree polynomial parameters.
    private void
    solveQuadratic(double a, double b, double c, com.irurueta.algebra.Complex x1, com.irurueta.algebra.Complex x2)
    Finds 2nd degree polynomial roots

    Methods inherited from class com.irurueta.numerical.roots.PolynomialRootsEstimator

    areRootsAvailable, getRoots, isReady, setPolynomialParameters

    Methods inherited from class com.irurueta.numerical.roots.RootEstimator

    isLocked

    Methods inherited from class java.lang.Object

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

    • EPS

      public static final double EPS
      Constant defining machine precision.
      See Also:
    • VALID_POLY_PARAMS_LENGTH

      public static final int VALID_POLY_PARAMS_LENGTH
      Number of parameters valid for a second degree polynomial.
      See Also:
    • realPolyParams

      private double[] realPolyParams
      Array containing parameters of a second degree polynomial.
  • Constructor Details

    • SecondDegreePolynomialRootsEstimator

      public SecondDegreePolynomialRootsEstimator()
      Empty constructor.
    • SecondDegreePolynomialRootsEstimator

      public SecondDegreePolynomialRootsEstimator(double[] polyParams)
      Constructor.
      Parameters:
      polyParams - Array containing polynomial parameters.
      Throws:
      IllegalArgumentException - Raised if the length of the provided array is not valid.
  • Method Details

    • setPolynomialParameters

      public void setPolynomialParameters(double[] polyParams) throws LockedException
      Set array of second degree polynomial parameters. A second degree polynomial is defined by p(x) = a * x^2 + b * x + c, and the array must be provided as [c, b, a]. Note: This class only supports real polynomial parameters
      Parameters:
      polyParams - Array containing polynomial parameters.
      Throws:
      LockedException - Raised if this instance is locked.
      IllegalArgumentException - Raised if the length of the provided array is not valid.
    • getRealPolynomialParameters

      public double[] getRealPolynomialParameters() throws NotAvailableException
      Returns array of second degree polynomial parameters. A second degree polynomial is defined by p(x) = a * x^2 + b * x + c, and the array is returned as [c, b, a]. Note: This class only supports real polynomial parameters
      Returns:
      Array of first degree polynomial parameters
      Throws:
      NotAvailableException - Raised if polynomial parameter have not yet been provided
    • arePolynomialParametersAvailable

      public boolean arePolynomialParametersAvailable()
      Returns boolean indicating whether REAL polynomial parameters have been provided and is available for retrieval. Note: This class only supports real polynomial parameters
      Overrides:
      arePolynomialParametersAvailable in class PolynomialRootsEstimator
      Returns:
      True if available, false otherwise
    • getPolynomialParameters

      public com.irurueta.algebra.Complex[] getPolynomialParameters() throws NotAvailableException
      This method will always raise a NotAvailableException because this class only supports REAL polynomial parameters
      Overrides:
      getPolynomialParameters in class PolynomialRootsEstimator
      Returns:
      always throws NotAvailableException
      Throws:
      NotAvailableException - always thrown
    • estimate

      Estimates the roots of provided polynomial.
      Overrides:
      estimate in class RootEstimator
      Throws:
      LockedException - Raised if this instance is locked estimating roots.
      NotReadyException - Raised if this instance is not ready because polynomial parameters have not been provided
      RootEstimationException - Raised if roots cannot be estimated for some reason
    • isSecondDegree

      public static boolean isSecondDegree(double[] polyParams)
      Returns boolean indicating whether provided array of polynomial parameters correspond to a valid second degree polynomial. A second degree polynomial is defined by p(x) = a * x^2 + b * x + c, and the array is returned as [a, b, a]. Note: This class only supports real polynomial parameters
      Parameters:
      polyParams - Array containing polynomial parameters
      Returns:
      True if is a second degree polynomial, false otherwise
    • isSecondDegree

      public boolean isSecondDegree() throws NotReadyException
      Returns boolean indicating whether polynomial parameters provided to this instance correspond to a valid second degree polynomial. A second degree polynomial is defined by p(x) = a * x^2 + b * x + c, and the array is returned as [c, b, a]. Note: This class only supports real polynomial parameters
      Returns:
      True if is a second degree polynomial, false otherwise
      Throws:
      NotReadyException - Raised if this instance is not ready because an array of polynomial parameters has not yet been provided.
    • hasTwoDistinctRealRoots

      public boolean hasTwoDistinctRealRoots(double[] polyParams)
      Returns boolean indicating whether the roots of the polynomial are two distinct and real roots or not. Because this class only supports polynomials with real parameters, we know that for second degree polynomials that have two distinct roots, its roots must be either real or complex conjugate.
      Parameters:
      polyParams - Array containing polynomial parameters
      Returns:
      True if roots are distinct and real, false otherwise
    • hasTwoDistinctRealRoots

      public boolean hasTwoDistinctRealRoots() throws NotReadyException
      Returns boolean indicating whether the roots of the polynomial are two distinct and real roots or not. Because this class only supports polynomials with real parameters, we know that for second degree polynomials that have two distinct roots, its roots must be either real or complex conjugate.
      Returns:
      True if roots are distinct and real, false otherwise
      Throws:
      NotReadyException - Raised if polynomial parameters haven't yet been provided
    • hasDoubleRoot

      public static boolean hasDoubleRoot(double[] polyParams)
      Returns boolean indicating whether a second degree polynomial has multiple roots (for the 2nd degree case this means 2 equal roots) This is true for polynomials of the form (x - r)^2 = x^2 - 2 * r * x + r^2, where r is the double root
      Parameters:
      polyParams - Array containing polynomial parameters
      Returns:
      True if it has double root, false otherwise
    • hasDoubleRoot

      public boolean hasDoubleRoot() throws NotReadyException
      Returns boolean indicating whether this second degree polynomial has multiple roots (for the 2nd degree case this means 2 equal roots) This is true for polynomials of the form (x - r)^2 = x^2 - 2 * r * x + r^2, where r is the double root
      Returns:
      True if it has double root, false otherwise
      Throws:
      NotReadyException - Raised if polynomial parameters haven't yet been provided.
    • hasTwoComplexConjugateRoots

      public static boolean hasTwoComplexConjugateRoots(double[] polyParams)
      Returns boolean indicating whether the roots of the polynomial are two complex conjugate roots or not. Because this class only supports polynomials with real parameters, we know that for second degree polynomials that have two distinct roots, its roots must be either real or complex conjugate.
      Parameters:
      polyParams - Array containing polynomial parameters
      Returns:
      True if roots are complex conjugate, false otherwise
    • hasTwoComplexConjugateRoots

      public boolean hasTwoComplexConjugateRoots() throws NotReadyException
      Returns boolean indicating whether the roots of the polynomial are two complex conjugate roots or not. Because this class only supports polynomials with real parameters, we know that for second degree polynomials that have two distinct roots, its roots must be either real or complex conjugate.
      Returns:
      True if roots are complex conjugate, false otherwise
      Throws:
      NotReadyException - Raised if polynomial parameters haven't yet been provided
    • internalSetPolynomialParameters

      protected void internalSetPolynomialParameters(com.irurueta.algebra.Complex[] polyParams)
      This method will always raise an IllegalArgumentException because this class only supports REAL polynomial parameters
      Specified by:
      internalSetPolynomialParameters in class PolynomialRootsEstimator
      Parameters:
      polyParams - Polynomial parameters.
    • getDiscriminant

      private static double getDiscriminant(double[] polyParams)
      Internal method to compute the discriminant of a 2nd degree polynomial. Discriminants are helpful to determine properties of a 2nd degree polynomial
      Parameters:
      polyParams - Array containing polynomial parameters
      Returns:
      Value of discriminant
    • solveQuadratic

      private void solveQuadratic(double a, double b, double c, com.irurueta.algebra.Complex x1, com.irurueta.algebra.Complex x2)
      Finds 2nd degree polynomial roots
      Parameters:
      a - 1st parameter
      b - 2nd parameter
      c - 3rd parameter
      x1 - 1st root (output parameter)
      x2 - 2nd root (output parameter)
    • internalSetPolynomialParameters

      private void internalSetPolynomialParameters(double[] polyParams)
      Internal method to set array of second degree polynomial parameters. A second degree polynomial is defined by p(x) = a * x^2 + b * x + c, and the array must be provided as [c, b, a]. Note: This class only supports real polynomial parameters This method does not check if this instance is locked.
      Parameters:
      polyParams - Array containing polynomial parameters.
      Throws:
      IllegalArgumentException - Raised if the length of the provided array is not valid.