Class PolynomialRoots
Copyright (c) 2020-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Method Summary
Modifier and TypeMethodDescriptionstatic Complex[]
cubicRoots
(double c2, double c1, double c0) CUBIC POLYNOMIAL ROOT SOLVER.static Complex[]
cubicRoots
(double c2, double c1, double c0, boolean verbose) CUBIC POLYNOMIAL ROOT SOLVER.static Complex[]
cubicRoots
(double c3, double c2, double c1, double c0) CUBIC POLYNOMIAL ROOT SOLVER.static Complex[]
linearRoots
(double q0) LINEAR POLYNOMIAL ROOT SOLVER.static Complex[]
linearRoots
(double q1, double q0) LINEAR POLYNOMIAL ROOT SOLVER.static Complex[]
quadraticRoots
(double q1, double q0) QUADRATIC POLYNOMIAL ROOT SOLVERstatic Complex[]
quadraticRoots
(double q2, double q1, double q0) QUADRATIC POLYNOMIAL ROOT SOLVERstatic Complex[]
quarticRoots
(double q3, double q2, double q1, double q0) QUARTIC POLYNOMIAL ROOT SOLVERstatic Complex[]
quarticRoots
(double q3, double q2, double q1, double q0, boolean verbose) QUARTIC POLYNOMIAL ROOT SOLVERstatic Complex[]
quarticRoots
(double q4, double q3, double q2, double q1, double q0) QUARTIC POLYNOMIAL ROOT SOLVER
-
Method Details
-
linearRoots
LINEAR POLYNOMIAL ROOT SOLVER.Calculates the root of the linear polynomial:
q1 * x + q0
Unlike the quadratic, cubic and quartic code, this is NOT derived from that Fortran90 code; it was added for completenes.- Parameters:
q1
- double; coefficient of the x termq0
- double; independent coefficient- Returns:
- Complex[]; the roots of the equation
-
linearRoots
LINEAR POLYNOMIAL ROOT SOLVER.Calculates the root of the linear polynomial:
x + q0
Unlike the quadratic, cubic and quartic code, this is NOT derived from that Fortran90 code; it was added for completenes.- Parameters:
q0
- double; independent coefficient- Returns:
- Complex[]; the roots of the equation
-
quadraticRoots
QUADRATIC POLYNOMIAL ROOT SOLVERCalculates all real + complex roots of the quadratic polynomial:
q2 * x^2 + q1 * x + q0
The code checks internally if rescaling of the coefficients is needed to avoid overflow.The order of the roots is as follows:
1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last).
2) Since there can be only one complex conjugate pair root, no order is necessary.
q1 : coefficient of x term q0 : independent coefficient- Parameters:
q2
- double; coefficient of the quadratic termq1
- double; coefficient of the x termq0
- double; independent coefficient- Returns:
- Complex[]; the roots of the equation
-
quadraticRoots
QUADRATIC POLYNOMIAL ROOT SOLVERCalculates all real + complex roots of the quadratic polynomial:
x^2 + q1 * x + q0
The code checks internally if rescaling of the coefficients is needed to avoid overflow.The order of the roots is as follows:
1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last).
2) Since there can be only one complex conjugate pair root, no order is necessary.
q1 : coefficient of x term q0 : independent coefficient- Parameters:
q1
- double; coefficient of the x termq0
- double; independent coefficient- Returns:
- Complex[]; the roots of the equation
-
cubicRoots
CUBIC POLYNOMIAL ROOT SOLVER.Calculates all (real and complex) roots of the cubic polynomial:
c3 * x^3 + c2 * x^2 + c1 * x + c0
The first real root (which always exists) is obtained using an optimized Newton-Raphson scheme. The other remaining roots are obtained through composite deflation into a quadratic.The cubic root solver can handle any size of cubic coefficients and there is no danger of overflow due to proper rescaling of the cubic polynomial. The order of the roots is as follows: 1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last). 2) Since there can be only one complex conjugate pair root, no order is necessary. 3) All real roots precede the complex ones.
- Parameters:
c3
- double; coefficient of the cubic termc2
- double; coefficient of the quadratic termc1
- double; coefficient of the linear termc0
- double; coefficient of the independent term- Returns:
- Complex[]; array of Complex with all the roots
-
cubicRoots
CUBIC POLYNOMIAL ROOT SOLVER.Calculates all (real and complex) roots of the cubic polynomial:
x^3 + c2 * x^2 + c1 * x + c0
The first real root (which always exists) is obtained using an optimized Newton-Raphson scheme. The other remaining roots are obtained through composite deflation into a quadratic.The cubic root solver can handle any size of cubic coefficients and there is no danger of overflow due to proper rescaling of the cubic polynomial. The order of the roots is as follows: 1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last). 2) Since there can be only one complex conjugate pair root, no order is necessary. 3) All real roots precede the complex ones.
- Parameters:
c2
- double; coefficient of the quadratic termc1
- double; coefficient of the linear termc0
- double; coefficient of the independent term- Returns:
- Complex[]; array of Complex with all the roots
-
cubicRoots
CUBIC POLYNOMIAL ROOT SOLVER.Calculates all (real and complex) roots of the cubic polynomial:
x^3 + c2 * x^2 + c1 * x + c0
The first real root (which always exists) is obtained using an optimized Newton-Raphson scheme. The other remaining roots are obtained through composite deflation into a quadratic. An option for printing detailed info about the intermediate stages in solving the cubic is available.The cubic root solver can handle any size of cubic coefficients and there is no danger of overflow due to proper rescaling of the cubic polynomial. The order of the roots is as follows: 1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last). 2) Since there can be only one complex conjugate pair root, no order is necessary. 3) All real roots precede the complex ones.
- Parameters:
c2
- double; coefficient of the quadratic termc1
- double; coefficient of the linear termc0
- double; coefficient of the independent termverbose
- boolean; if true; produce debugging output; if false; do not produce debugging output- Returns:
- Complex[]; array of Complex with all the roots
-
quarticRoots
QUARTIC POLYNOMIAL ROOT SOLVERCalculates all real + complex roots of the quartic polynomial:
q4 * x^4 + q3 * x^3 + q2 * x^2 + q1 * x + q0The quartic root solver can handle any size of quartic coefficients and there is no danger of overflow, due to proper rescaling of the quartic polynomial.
The order of the roots is as follows:
1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last).
2) For complex conjugate pair roots, the order is according to the algebraic value of their real parts (largest positive first). If the real parts are equal, the order is according to the algebraic value of their imaginary parts (largest first).
3) All real roots precede the complex ones.- Parameters:
q4
- double; coefficient of the quartic termq3
- double; coefficient of the cubic termq2
- double; coefficient of the quadratic termq1
- double; coefficient of the linear termq0
- double; independent coefficient- Returns:
- Complex[]; array of Complex with all the roots
-
quarticRoots
QUARTIC POLYNOMIAL ROOT SOLVERCalculates all real + complex roots of the quartic polynomial:
x^4 + q3 * x^3 + q2 * x^2 + q1 * x + q0The quartic root solver can handle any size of quartic coefficients and there is no danger of overflow, due to proper rescaling of the quartic polynomial.
The order of the roots is as follows:
1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last).
2) For complex conjugate pair roots, the order is according to the algebraic value of their real parts (largest positive first). If the real parts are equal, the order is according to the algebraic value of their imaginary parts (largest first).
3) All real roots precede the complex ones.- Parameters:
q3
- double; coefficient of the cubic termq2
- double; coefficient of the quadratic termq1
- double; coefficient of the linear termq0
- double; independent coefficient- Returns:
- Complex[]; array of Complex with all the roots
-
quarticRoots
QUARTIC POLYNOMIAL ROOT SOLVERCalculates all real + complex roots of the quartic polynomial:
x^4 + q3 * x^3 + q2 * x^2 + q1 * x + q0An option for printing detailed info about the intermediate stages in solving the quartic is available. This enables a detailed check in case something went wrong and the roots obtained are not proper.
The quartic root solver can handle any size of quartic coefficients and there is no danger of overflow, due to proper rescaling of the quartic polynomial.The order of the roots is as follows:
1) For real roots, the order is according to their algebraic value on the number scale (largest positive first, largest negative last).
2) For complex conjugate pair roots, the order is according to the algebraic value of their real parts (largest positive first). If the real parts are equal, the order is according to the algebraic value of their imaginary parts (largest first).
3) All real roots precede the complex ones.- Parameters:
q3
- double; coefficient of the cubic termq2
- double; coefficient of the quadratic termq1
- double; coefficient of the linear termq0
- double; independent coefficientverbose
- boolean; if true; produce debugging output; if false; do not produce debugging output- Returns:
- Complex[]; array of Complex with all the roots
-