Qu

roots

Builtin index · Statistics & ML

result = roots(p)

Input: p · Output: result

What it is

Roots of the polynomial whose coefficients p (a real Vec, highest power first, the order polyfit/polyval use) are given, as the eigenvalues of the companion matrix. Leading zeros are dropped; trailing zeros come back as exact 0 roots (last); a constant or all-zero p has no roots and gives an empty Vec.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = roots(p)
p Vec or matrixnot documented yet
eps^(1/m) —a double root to ~1e-8
Returns a Vec when every root is real, otherwise a CVec. The order of the roots is unspecified (sort the result if you need one). Every answer is checked against the polynomial, and if the eigenvalue solver fails or is inaccurate the roots are recomputed by an Aberth iteration polished with Newton steps, so a result is never returned unverified. A multiple root of multiplicity m can only be found to about eps^(1/m) (a double root to ~1e-8), which is a property of the problem, not of the method. Errors: empty p, non-finite or complex coefficients, a non-vector, wrong argument count.

Examples

No documentation example calls this form yet. The Statistics & ML chapter is where one belongs.