Numerical roots of a univariate polynomial

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


numeric::polyroots(eqs, <FixedPrecision>, <SquareFree>, <Factor>, <NoWarning>)


numeric::polyroots(eqs) returns numerical approximations of all real and complex roots of the univariate polynomials eqs.

The coefficients may be real or complex numbers. Also symbolic coefficients are accepted if they can be converted to floats.

The trivial polynomial eqs = 0 results in an error message. The empty list is returned for constant polynomials eqs ≠ 0.

Multiple roots are listed according to their multiplicities, i.e., the length of the root list coincides with the degree of eqs.

The root list is sorted by numeric::sort.

Up to roundoff effects, the numerical roots should be accurate to DIGITS significant digits, unless the option FixedPrecision is used.

All floating-point entries in eqs are internally approximated by rational numbers: numeric::polyroots(eqs) computes the roots of numeric::rationalize(eqs, Minimize).

For polynomial expressions in factored form, the numerical search is applied to each factor separately.

It is recommended to use numeric::realroots or polylib::realroots if eqs is a real polynomial and only real roots are of interest.

Environment Interactions

The function is sensitive to the environment variable DIGITS, which determines the numerical working precision.


Example 1

Both polynomial expressions as well as DOM_POLY objects may be used to specify the polynomial:

numeric::polyroots(x^3 - 3*x - sqrt(2))

numeric::polyroots(PI*z^4 + I*z + 0.1)

numeric::polyroots(poly(x^5 - x^2, [x]))

Example 2

The following polynomial has exact coefficients:

p := poly((x - 1)*(x - PI)^3, [x]): 

Note that roundoff errors in the coefficients of eqs have a dramatic effect on multiple roots:

p := poly((x - 1.0)*(x - float(PI))^3, [x]): 

These are the roots of the following rationalized polynomial:

numeric::rationalize(p, Minimize)

delete p:

Example 3

The multiple root of the following polynomial can only be computed with restricted precision by fixed precision arithmetic:

p := poly((x^2 - 6*x +8)*(x - I/3)^5, [x]):
numeric::polyroots(p, FixedPrecision)

Without the option FixedPrecision, the working precision is increased internally to compute better approximations:


delete p:

Example 4

The following polynomial has badly separated roots. numeric::polyroots does not manage to separate them properly:

p := poly(_mult((x - 1 - i/10^9) $ i=0..5), [x]):

One can preprocess the polynomial by a symbolic factorization:

numeric::polyroots(p, Factor)

Alternatively, one can increase the working precision to separate the roots:

DIGITS := 20:

delete p, DIGITS:



A univariate polynomial expression or a univariate polynomial of domain type DOM_POLY. The function also accepts a list, set, array, or matrix (Cat::Matrix) of polynomial expressions.



This option provides the fastest way to obtain approximations of the roots by a numerical search with a fixed internal precision of 2 DIGITS decimal places.

Note that badly isolated roots or multiple roots will usually not be approximated to DIGITS decimals when using this option. The problem of finding such roots is numerically ill-conditioned, i.e., such roots cannot be found to full precision with fixed precision arithmetic. Typically, a q-fold root will be approximated only to about decimal places. Cf. Example 3.

Without this option, numeric::polyroots internally increases the working precision until all roots are found to DIGITS decimal places.


With this option, a symbolic square free factorization is computed via polylib::sqrfree(eqs). The numerical root finding algorithm is then applied to each square free factor.

This option is recommended, when p is known to have multiple roots. Such roots force numeric::polyroots to increase the working precision internally increasing the costs of the numerical search. A square free factorization reduces the multiplicity of each root to one, speeding up the final numerical search.

For polynomials with real rational coefficients, a square free factorization is always used, i.e., this option does not have any effect for such polynomials. For all other types of coefficients, a square free factorization may be costly and must be requested by this option.

Multiple roots of eqs can be successfully dealt with by this option. However, for badly separated distinct roots the square free factorization will not improve the performance of the numerical search.


With this option, a symbolic factorizations of eqs via factor are computed. The numerical root finding algorithm is then applied to each factor.

This option is useful, when eqs can be successfully factorized (e.g., when each expression from eqs has multiple roots). The numerical search on the factors is much more efficient than the search on the original polynomial. On the other hand, symbolic factorization of eqs may be costly.


Suppresses warnings

Return Values

List of numerical roots.


The numerical root finding algorithm implemented by numeric::polyroots is Laguerre's method: W.H. Press, B.P. Flannery, S.A. Teukolsky and W.T. Vetterling: Numerical Recipes in C, Cambridge University Press, 1988.