PolynomialSolver
Finds all complex roots of a univariate polynomial numerically. Coefficient arrays use ascending powers: the element at index
`k`is the coefficient of
`x^k`. Polynomial and string inputs are converted to that representation before solving. Linear and quadratic inputs are handled directly; higher degrees use simultaneous Aberth iteration followed by Newton refinement.
The solver temporarily changes the global
`decimal.js`precision while roots runs and restores the previous precision before returning. The requested precision controls the numerical work, while
`epsilon`controls convergence and cleanup of numerical noise. Roots are returned once per polynomial degree, so repeated roots can appear as repeated nearby approximations. This class finds numerical roots; it does not certify completeness or exact multiplicities for ill-conditioned polynomials.
Examples
const solver = new PolynomialSolver('x^2+1', 'x');
const roots = solver.roots();Members
PolynomialSolver(input: string | Decimal[] | Polynomial, variable?: string, precision: number, epsilon?: Decimal): PolynomialSolverConstructorCreates a polynomial root solver.
UnexpectedInputError If a string input is multivariate or uses a variable different from
`variable`.
Parameters
| Name | Type | Description |
|---|---|---|
input | string | Decimal[] | Polynomial | A polynomial, a polynomial string, or ascending-power coefficients. |
variable | string | Variable expected in a string input. It is used to reject a conflicting or multivariate string. |
precision | number | Working `decimal.js` precision used while finding roots. |
epsilon | Decimal | Numerical convergence tolerance. Defaults to `1e-14`. |
Returns
roots(asExpressions?: true): Expression[]MethodComputes the roots of the configured polynomial. Leading zero coefficients are ignored. A constant or zero coefficient array produces an empty result. Passing
`false`returns the numeric Complex values directly; otherwise each root is converted to an Expression after restoring the caller's Decimal precision.
Parameters
| Name | Type | Description |
|---|---|---|
asExpressions | true | Whether to convert roots to symbolic expressions. Defaults to `true`. |
Returns
Expression[] — One root value per effective polynomial degree, including repeated numerical approximations for repeated roots.
