Package com.irurueta.numerical.roots
Class SecondDegreePolynomialRootsEstimator
java.lang.Object
com.irurueta.numerical.roots.RootEstimator
com.irurueta.numerical.roots.PolynomialRootsEstimator
com.irurueta.numerical.roots.SecondDegreePolynomialRootsEstimator
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
FieldsModifier and TypeFieldDescriptionstatic final doubleConstant defining machine precision.private double[]Array containing parameters of a second degree polynomial.static final intNumber of parameters valid for a second degree polynomial.Fields inherited from class com.irurueta.numerical.roots.PolynomialRootsEstimator
polyParams, rootsFields inherited from class com.irurueta.numerical.roots.RootEstimator
locked -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor.SecondDegreePolynomialRootsEstimator(double[] polyParams) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns boolean indicating whether REAL polynomial parameters have been provided and is available for retrieval.voidestimate()Estimates the roots of provided polynomial.private static doublegetDiscriminant(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 parametersdouble[]Returns array of second degree polynomial parameters.booleanReturns 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 rootstatic booleanhasDoubleRoot(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 rootbooleanReturns boolean indicating whether the roots of the polynomial are two complex conjugate roots or not.static booleanhasTwoComplexConjugateRoots(double[] polyParams) Returns boolean indicating whether the roots of the polynomial are two complex conjugate roots or not.booleanReturns boolean indicating whether the roots of the polynomial are two distinct and real roots or not.booleanhasTwoDistinctRealRoots(double[] polyParams) Returns boolean indicating whether the roots of the polynomial are two distinct and real roots or not.private voidinternalSetPolynomialParameters(double[] polyParams) Internal method to set array of second degree polynomial parameters.protected voidinternalSetPolynomialParameters(com.irurueta.algebra.Complex[] polyParams) This method will always raise an IllegalArgumentException because this class only supports REAL polynomial parametersbooleanReturns boolean indicating whether polynomial parameters provided to this instance correspond to a valid second degree polynomial.static booleanisSecondDegree(double[] polyParams) Returns boolean indicating whether provided array of polynomial parameters correspond to a valid second degree polynomial.voidsetPolynomialParameters(double[] polyParams) Set array of second degree polynomial parameters.private voidsolveQuadratic(double a, double b, double c, com.irurueta.algebra.Complex x1, com.irurueta.algebra.Complex x2) Finds 2nd degree polynomial rootsMethods inherited from class com.irurueta.numerical.roots.PolynomialRootsEstimator
areRootsAvailable, getRoots, isReady, setPolynomialParametersMethods inherited from class com.irurueta.numerical.roots.RootEstimator
isLocked
-
Field Details
-
EPS
public static final double EPSConstant defining machine precision.- See Also:
-
VALID_POLY_PARAMS_LENGTH
public static final int VALID_POLY_PARAMS_LENGTHNumber of parameters valid for a second degree polynomial.- See Also:
-
realPolyParams
private double[] realPolyParamsArray 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
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
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:
arePolynomialParametersAvailablein classPolynomialRootsEstimator- Returns:
- True if available, false otherwise
-
getPolynomialParameters
This method will always raise a NotAvailableException because this class only supports REAL polynomial parameters- Overrides:
getPolynomialParametersin classPolynomialRootsEstimator- Returns:
- always throws NotAvailableException
- Throws:
NotAvailableException- always thrown
-
estimate
Estimates the roots of provided polynomial.- Overrides:
estimatein classRootEstimator- Throws:
LockedException- Raised if this instance is locked estimating roots.NotReadyException- Raised if this instance is not ready because polynomial parameters have not been providedRootEstimationException- 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
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
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
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
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:
internalSetPolynomialParametersin classPolynomialRootsEstimator- 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 parameterb- 2nd parameterc- 3rd parameterx1- 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.
-