This class implements the calculation of all the real roots of a real polynomial of degree <= 4 using direct algebraic methods. The implementation uses Ferrari's method for quartics, Cardano's formula for cubics, and numerically stable algorithms for quadratics and linear equations.
More...
#include <math_DirectPolynomialRoots.hxx>
|
| | math_DirectPolynomialRoots (const double theA, const double theB, const double theC, const double theD, const double theE) |
| | Computes all the real roots of the quartic polynomial Ax^4 + Bx^3 + Cx^2 + Dx + E = 0 using Ferrari's method.
|
| |
| | math_DirectPolynomialRoots (const double theA, const double theB, const double theC, const double theD) |
| | Computes all the real roots of the cubic polynomial Ax^3 + Bx^2 + Cx + D = 0 using Cardano's method with Vieta substitution.
|
| |
| | math_DirectPolynomialRoots (const double theA, const double theB, const double theC) |
| | Computes all the real roots of the quadratic polynomial Ax^2 + Bx + C = 0 using numerically stable formulas.
|
| |
| | math_DirectPolynomialRoots (const double theA, const double theB) |
| | Computes the real root of the linear equation Ax + B = 0.
|
| |
| bool | IsDone () const |
| | Returns true if the computations are successful, otherwise returns false. Computations may fail due to numerical issues or overflow conditions.
|
| |
| bool | InfiniteRoots () const |
| | Returns true if there is an infinity of roots, otherwise returns false. This occurs only for the degenerate linear case 0*x + 0 = 0.
|
| |
| int | NbSolutions () const |
| | Returns the number of distinct real roots found. An exception is raised if there are an infinity of roots. For multiple roots, this counts each root according to its multiplicity.
|
| |
| double | Value (const int theIndex) const |
| | Returns the value of the Nth root in default ordering. The default ordering may vary depending on the algorithm used. An exception is raised if there are an infinity of roots. Exception RangeError is raised if theIndex is < 1 or theIndex > NbSolutions.
|
| |
| void | Dump (Standard_OStream &theStream) const |
| | Prints diagnostic information about the current state of the solver. Outputs computation status, number of roots, and individual root values. This method is used to redefine the operator << for debugging purposes.
|
| |
|
| void | Solve (const double theA, const double theB, const double theC, const double theD, const double theE) |
| | Solves quartic equation Ax^4 + Bx^3 + Cx^2 + Dx + E = 0 using Ferrari's method with modern numerical enhancements for stability and accuracy.
|
| |
| void | Solve (const double theA, const double theB, const double theC, const double theD) |
| | Solves cubic equation Ax^3 + Bx^2 + Cx + D = 0 using Cardano's method with Vieta substitution and trigonometric solution for stability.
|
| |
| void | Solve (const double theA, const double theB, const double theC) |
| | Solves quadratic equation Ax^2 + Bx + C = 0 using numerically stable formulas to avoid catastrophic cancellation.
|
| |
| void | Solve (const double theA, const double theB) |
| | Solves linear equation Ax + B = 0 with proper handling of degenerate cases.
|
| |
This class implements the calculation of all the real roots of a real polynomial of degree <= 4 using direct algebraic methods. The implementation uses Ferrari's method for quartics, Cardano's formula for cubics, and numerically stable algorithms for quadratics and linear equations.
Key features:
- Robust numerical algorithms with coefficient scaling
- Newton-Raphson root refinement for improved accuracy
- Proper handling of degenerate and edge cases
- Multiple root detection and infinite solution handling
- Scientific reference ordering for deterministic results
Once found, all roots are polished using the Newton-Raphson method to achieve maximum numerical precision.
◆ math_DirectPolynomialRoots() [1/4]
| math_DirectPolynomialRoots::math_DirectPolynomialRoots |
( |
const double | theA, |
|
|
const double | theB, |
|
|
const double | theC, |
|
|
const double | theD, |
|
|
const double | theE ) |
Computes all the real roots of the quartic polynomial Ax^4 + Bx^3 + Cx^2 + Dx + E = 0 using Ferrari's method.
The algorithm:
- Checks for degree reduction (A ~= 0)
- Normalizes and scales coefficients for numerical stability
- Solves Ferrari's resolvent cubic equation
- Factors quartic into two quadratic equations
- Solves both quadratics independently
- Refines all roots using Newton-Raphson method
- Parameters
-
| theA | coefficient of x^4 term |
| theB | coefficient of x^3 term |
| theC | coefficient of x^2 term |
| theD | coefficient of x term |
| theE | constant term |
◆ math_DirectPolynomialRoots() [2/4]
| math_DirectPolynomialRoots::math_DirectPolynomialRoots |
( |
const double | theA, |
|
|
const double | theB, |
|
|
const double | theC, |
|
|
const double | theD ) |
Computes all the real roots of the cubic polynomial Ax^3 + Bx^2 + Cx + D = 0 using Cardano's method with Vieta substitution.
The algorithm:
- Transforms to depressed cubic t^3 + Pt + Q = 0
- Computes discriminant Delta = -4P^3/27 - Q^2/4
- Uses trigonometric method for Delta < 0 (three real roots)
- Uses Cardano's formula for Delta > 0 (one real root)
- Handles multiple roots when Delta = 0
- Applies Newton-Raphson refinement
- Parameters
-
| theA | coefficient of x^3 term |
| theB | coefficient of x^2 term |
| theC | coefficient of x term |
| theD | constant term |
◆ math_DirectPolynomialRoots() [3/4]
| math_DirectPolynomialRoots::math_DirectPolynomialRoots |
( |
const double | theA, |
|
|
const double | theB, |
|
|
const double | theC ) |
Computes all the real roots of the quadratic polynomial Ax^2 + Bx + C = 0 using numerically stable formulas.
The algorithm avoids catastrophic cancellation by using:
- Discriminant with error bounds: Delta = B^2 - 4AC
- Stable root formulas based on sign of B
- Newton-Raphson refinement for improved accuracy
- Parameters
-
| theA | coefficient of x^2 term |
| theB | coefficient of x term |
| theC | constant term |
◆ math_DirectPolynomialRoots() [4/4]
| math_DirectPolynomialRoots::math_DirectPolynomialRoots |
( |
const double | theA, |
|
|
const double | theB ) |
Computes the real root of the linear equation Ax + B = 0.
Handles all cases:
- A != 0: unique solution x = -B/A
- A = 0, B != 0: no solution (inconsistent)
- A = 0, B = 0: infinite solutions (identity)
- Parameters
-
| theA | coefficient of x term |
| theB | constant term |
◆ Dump()
Prints diagnostic information about the current state of the solver. Outputs computation status, number of roots, and individual root values. This method is used to redefine the operator << for debugging purposes.
- Parameters
-
| theStream | output stream for diagnostic information |
◆ InfiniteRoots()
| bool math_DirectPolynomialRoots::InfiniteRoots |
( |
| ) |
const |
|
inline |
Returns true if there is an infinity of roots, otherwise returns false. This occurs only for the degenerate linear case 0*x + 0 = 0.
◆ IsDone()
| bool math_DirectPolynomialRoots::IsDone |
( |
| ) |
const |
|
inline |
Returns true if the computations are successful, otherwise returns false. Computations may fail due to numerical issues or overflow conditions.
◆ NbSolutions()
| int math_DirectPolynomialRoots::NbSolutions |
( |
| ) |
const |
|
inline |
Returns the number of distinct real roots found. An exception is raised if there are an infinity of roots. For multiple roots, this counts each root according to its multiplicity.
◆ Solve() [1/4]
Solves linear equation Ax + B = 0 with proper handling of degenerate cases.
Handles all cases:
- Normal case (A != 0): unique solution
- Inconsistent case (A = 0, B != 0): no solution
- Identity case (A = 0, B = 0): infinite solutions
- Parameters
-
| theA | coefficient of x term |
| theB | constant term |
◆ Solve() [2/4]
Solves quadratic equation Ax^2 + Bx + C = 0 using numerically stable formulas to avoid catastrophic cancellation.
Features:
- Discriminant computation with error bounds
- Stable root extraction formulas
- Proper handling of near-zero discriminant (double roots)
- Newton-Raphson refinement
- Parameters
-
| theA | coefficient of x^2 term |
| theB | coefficient of x term |
| theC | constant term |
◆ Solve() [3/4]
Solves cubic equation Ax^3 + Bx^2 + Cx + D = 0 using Cardano's method with Vieta substitution and trigonometric solution for stability.
Implementation features:
- Transformation to depressed cubic form
- Discriminant-based method selection
- Trigonometric solution for three real roots
- Cardano's formula for one real root
- Special handling for multiple roots
- Coefficient scaling for numerical robustness
- Parameters
-
| theA | coefficient of x^3 term |
| theB | coefficient of x^2 term |
| theC | coefficient of x term |
| theD | constant term |
◆ Solve() [4/4]
Solves quartic equation Ax^4 + Bx^3 + Cx^2 + Dx + E = 0 using Ferrari's method with modern numerical enhancements for stability and accuracy.
Implementation details:
- Degree reduction check for nearly-zero leading coefficient
- Coefficient normalization and scaling for numerical stability
- Ferrari's resolvent cubic construction and solution
- Quartic factorization into two quadratic equations
- Newton-Raphson refinement of all roots
- Parameters
-
| theA | coefficient of x^4 term |
| theB | coefficient of x^3 term |
| theC | coefficient of x^2 term |
| theD | coefficient of x term |
| theE | constant term |
◆ Value()
| double math_DirectPolynomialRoots::Value |
( |
const int | theIndex | ) |
const |
|
inline |
Returns the value of the Nth root in default ordering. The default ordering may vary depending on the algorithm used. An exception is raised if there are an infinity of roots. Exception RangeError is raised if theIndex is < 1 or theIndex > NbSolutions.
- Parameters
-
| theIndex | root index (1-based) |
- Returns
- root value
The documentation for this class was generated from the following file: