Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions
math_DirectPolynomialRoots Class Reference

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>

Public Member Functions

 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.
 

Protected Member Functions

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.
 

Detailed Description

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:

Once found, all roots are polished using the Newton-Raphson method to achieve maximum numerical precision.

Constructor & Destructor Documentation

◆ 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:

  1. Checks for degree reduction (A ~= 0)
  2. Normalizes and scales coefficients for numerical stability
  3. Solves Ferrari's resolvent cubic equation
  4. Factors quartic into two quadratic equations
  5. Solves both quadratics independently
  6. Refines all roots using Newton-Raphson method
Parameters
theAcoefficient of x^4 term
theBcoefficient of x^3 term
theCcoefficient of x^2 term
theDcoefficient of x term
theEconstant 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:

  1. Transforms to depressed cubic t^3 + Pt + Q = 0
  2. Computes discriminant Delta = -4P^3/27 - Q^2/4
  3. Uses trigonometric method for Delta < 0 (three real roots)
  4. Uses Cardano's formula for Delta > 0 (one real root)
  5. Handles multiple roots when Delta = 0
  6. Applies Newton-Raphson refinement
Parameters
theAcoefficient of x^3 term
theBcoefficient of x^2 term
theCcoefficient of x term
theDconstant 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
theAcoefficient of x^2 term
theBcoefficient of x term
theCconstant 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
theAcoefficient of x term
theBconstant term

Member Function Documentation

◆ Dump()

void math_DirectPolynomialRoots::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.

Parameters
theStreamoutput 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]

void math_DirectPolynomialRoots::Solve ( const double theA,
const double theB )
protected

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
theAcoefficient of x term
theBconstant term

◆ Solve() [2/4]

void math_DirectPolynomialRoots::Solve ( const double theA,
const double theB,
const double theC )
protected

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
theAcoefficient of x^2 term
theBcoefficient of x term
theCconstant term

◆ Solve() [3/4]

void math_DirectPolynomialRoots::Solve ( const double theA,
const double theB,
const double theC,
const double theD )
protected

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
theAcoefficient of x^3 term
theBcoefficient of x^2 term
theCcoefficient of x term
theDconstant term

◆ Solve() [4/4]

void math_DirectPolynomialRoots::Solve ( const double theA,
const double theB,
const double theC,
const double theD,
const double theE )
protected

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
theAcoefficient of x^4 term
theBcoefficient of x^3 term
theCcoefficient of x^2 term
theDcoefficient of x term
theEconstant 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
theIndexroot index (1-based)
Returns
root value

The documentation for this class was generated from the following file: