Numerical Methods at work

Disclaimer:
Permission to use, copy, and distribute this software, and It’s documentation for any non-commercial purpose is hereby granted without fee, provided: THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL Henrik Vestermark, BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Polynomial Root finder

This Polynomial solver finds the real or complex roots (or zeros) of a polynomial of any degree with either real or complex coefficients. The method was original based on a modified Newton iteration method developed by Kaj Madsen back in the seventies, see: [K.Madsen: "A root finding algorithm based on Newton Method" Bit 13 1973 page 71-75]. However I have recently added other methods: Ostrowski, Halley's, Householder 3rd order, Jenkins-Traub, Laguerre's, Eigenvalue, Durand-Kerner, Aberth-Ehrlich, Chebyshev, Ostrowski Square root method, Arithmetic Mean Newton, Steffensen & Tangent Graeffe method. See the Authors paper on the subject Read more ... Notice that all methods are so called modified method's, which maintain there convergence rate even for multiple roots.

Polynomial Root Finder app icon

Use the root finder as an app on your phone or tablet — free, no app store needed, and it also works offline.

Open the app

iPhone/iPad: open the app in Safari, tap Share and then Add to Home Screen.
Android: open the app in Chrome and tap Install (or ⋮ → Add to Home screen).

QR code for https://www.hvks.com/Numerical/app/solver/ Scan with your phone
Polynomial Root Finder vs 1.66


Options      


  • Results
  • Plot Roots
  • Plot P(x) Values
  • Plot Convergence
  • Plot 3D Surface
  • Plot 2D Contour
  • Plot Polishing
  • Plot Sensitivity
  • Plot Comparison
  • Help
  • Method used
  • Why Polishing

Top: |P(x)| at each root as the method found it (circle), after polishing (diamond), and the error bound of plain double evaluation (dash). A method has to stop near that dash; polishing evaluates P(x) as if in twice double precision and continues below it. Values that are exactly 0 are drawn on the bottom line. Bottom: how far polishing moved each root, relative to |z|, compared with one ulp; the number of correct digits of the method's root is about \(-\log_{10}\) of that value.

The cluster plot (only shown when roots were grouped) is magnified around the final root. It shows the method's approximations, their Newton circles (each contains at least one root, and they overlap, which is why the approximations were grouped), the centroid where polishing started, the Newton steps on \(P^{(m-1)}\), and the verified \(m\)-fold root. Use the dropdown to switch between clusters.

How far can each root be trusted? The stored coefficients carry relative errors of about one unit roundoff \(u=2^{-53}\). Every point inside the contour marked \(k\) is an exact root of some polynomial whose coefficients differ from the given ones by a relative \(10^{k}\). A small region around a root means the root is well determined; a large region means a tiny change in the coefficients can move the root far. The condition number of a simple root is \(\kappa=\sum|a_k||z|^k/(|z|\,|P'(z)|)\), and it can lose about \(\log_{10}\kappa\) of its 16 digits; an \(m\)-fold root moves about \((m!\,u\sum|a_k||z|^k/|P^{(m)}(z)|)^{1/m}\). The values for each root are listed in the Results tab. Try Wilkinson's polynomial (x-1)(x-2)...(x-20).

Click Compare Methods to run all methods on the current polynomial. Time is the average over repeated solves. Correct digits are for each method's worst root before polishing, compared with the most accurate method's roots after polishing. Iterations are not directly comparable between methods: Durand-Kerner and Aberth-Ehrlich update all roots in each iteration, the Eigenvalue method counts QR iterations, and Graeffe counts root squaring steps (including restarts after a shift). The table is added to the Results tab.

Polynomial root finder

This polynomial solver finds all the real and complex roots of a polynomial of any degree with real or complex coefficients, \(a_nx^n+a_{n-1}x^{n-1}+\dots+a_1x+a_0\), with any of 14 methods. Everything runs in your browser in IEEE754 double precision.

Entering a polynomial

  • Type the polynomial as you would write it, e.g. x^3-3x+4, and press Find Roots. x^3 stands for x3. The terms can be in any order: -1.2+3.5x^3+4.5x-1.2E-1x is just as valid.
  • Numbers can have an exponent with e or E: 120, 1.20e2, 12E+1 and 1200E-1 are all 120.
  • Complex coefficients are written with i, in parentheses where needed: (3-i4)x^3-2x^2-i4x-3.
  • Products, quotients, powers and parentheses are expanded: (x-1)(x-2)^3 or (1+2*3x^4-5x^2)^3. Note that expanding a product rounds the coefficients to double precision; for large coefficients (above \(2^{53}\approx 9\cdot10^{15}\)) the stored polynomial then differs slightly from the one you typed, see the Root sensitivity report.
  • Test and Test Complex enter an example polynomial with real and with complex coefficients. Shift asks for a value c and prints the coefficients of P(x+c).

Methods and options

  • Method selects one of 14 methods: Newton (default), Halley, Ostrowski multi-point, Householder, Jenkins-Traub, Laguerre, Eigenvalue, Durand-Kerner, Aberth-Ehrlich, Chebyshev, Ostrowski square root, Arithmetic Mean Newton, Steffensen and Tangent Graeffe.
  • Compare Methods runs all 14 methods on the polynomial and reports time, iterations per root, correct digits of the worst root and the largest backward error. See the Plot Comparison tab.
  • Polish roots (on by default) refines every root on the original polynomial in twice the working precision and detects multiple roots. See the Why Polishing tab.
  • Verbose Mode prints every iteration step, including the safeguards of the method. It is the best way to see how a method approaches a root.
  • Display Iteration trail prints and plots the iterates of every root, the iteration statistics and the error polynomial (the polynomial rebuilt from the roots minus the original).
  • Display: Auto scaling scales the axes of the plots independently.

The results

The Results tab lists the roots X1, X2, ..., the polishing report, and a Root sensitivity report that says for each root how many digits the coefficients determine: a root with condition number \(\kappa\) can lose about \(\log_{10}\kappa\) of its 16 digits, and an \(m\)-fold root keeps only about \(16/m\). The plot tabs show the roots in the complex plane, \(|P|\) and the order of convergence along the iterations, \(|P(z)|\) as a 3D surface and as contours, the effect of polishing, the pseudozero sets of the polynomial (Plot Sensitivity) and the comparison of all methods.

Background

The methods, the stopping criteria, polishing and the test results are described in the paper Practical Implementation of Polynomial Root Finders at www.hvks.com/Numerical/papers.html.
Email: hve@hvks.com if you have any questions.
This version has been tested with current versions of Edge, Chrome, Firefox and Safari.

The default method: Newton's method as designed by Madsen

Let the polynomial be \(P(x)=a_nx^n+a_{n-1}x^{n-1}+\dots+a_1x+a_0\) with real or complex coefficients. The solver finds all roots of \(P(x)=0\). By default it uses Newton's method in the form developed by Kaj Madsen [K. Madsen, A root-finding algorithm based on Newton's method, BIT 13 (1973) 71-75], which is fast, reliable and handles the classical problems of Newton's method: poor starting points, saddle points and multiple roots. The same framework is used by the other Newton-type methods (Halley, Householder, Chebyshev, Ostrowski square root, Laguerre, Ostrowski multi-point, Arithmetic Mean Newton and Steffensen). The roots are found one at a time. Each root is divided out of the polynomial (deflation) and the search continues on the polynomial of one degree lower; the last one or two roots are found directly with the quadratic formula.
  • Starting point. The search starts inside a circle that contains no roots, so that the roots tend to be found in increasing order of modulus. Composite deflation, which combines forward and backward deflation, keeps the deflation stable whatever the order.
  • Stage 1. Far from a root every step is checked: if \(|P|\) increases, the step is shortened or rotated; if it decreases, longer steps \(m\cdot dz\), \(m=2,3,\dots\) are tried in the same direction. This gives quadratic convergence also to a root of multiplicity \(m\), without knowing \(m\) in advance.
  • Stage 2. When the iteration is known to converge, plain steps of the method are taken until the stopping criterion is met.
  • Stopping criterion. The iteration stops when \(|P(z)|\) is no larger than a bound on its own rounding error, so the root is as accurate as the evaluation allows: Kahan's bound at a real point, Adams' bound for real coefficients at a complex point [D. Adams, Comm. ACM 10 (1967) 655-658], and a running error bound for complex coefficients.
Check Verbose Mode to see the stages, the trial steps and the stopping criterion at work.

Root polishing: refining the roots after any method

When the Polish roots option is checked (the default), every root found by the selected method is refined before it is shown. It works the same way after all 14 methods, and it needs only ordinary IEEE754 double precision: no interval or arbitrary precision arithmetic.
Polishing is not a separate root finder. The selected method must first find all the roots approximately; polishing then takes them the last few digits to the limit that double precision allows.

Why polish the roots?

  • Deflation errors. Methods that find one root at a time divide each root out of the polynomial and continue on the smaller, deflated polynomial. Rounding errors in the deflation make the later roots slightly less accurate. Polishing refines every root against the original polynomial, so these errors disappear.
  • Rounding noise. Near a root, the computed value of \(P(x)\) in double precision is mostly rounding noise, so any method has to stop when \(|P(x)|\) reaches that noise level. Polishing evaluates \(P(x)\) more accurately, which lets it go further.
  • Multiple roots. At a root of multiplicity \(m\), ordinary double precision only gives about \(16/m\) correct digits: about 8 digits for a double root, 5 for a triple root. Polishing recognises multiple roots and returns them to full accuracy.

How it works

  • Accurate evaluation. \(P(x)\) is evaluated with the compensated Horner scheme. Each multiplication and addition in Horner's method is done with an error-free transformation (Knuth's TwoSum and Dekker's TwoProduct), which gives the rounded result together with its exact rounding error. The errors are added up in a second Horner recurrence and applied as a correction at the end. The result is as accurate as if \(P(x)\) had been computed in twice double precision (about 32 digits) and then rounded to double [Graillat, Langlois & Louvet 2009].
  • Newton steps on the original polynomial. Each root is improved by Newton's method \(x_{k+1}=x_k-P(x_k)/P'(x_k)\), with both \(P\) and \(P'\) evaluated in the accurate way. A step is only kept if it makes \(|P(x)|\) smaller, and a root may never move more than half way towards its nearest neighbour, so it can never jump to another root. Usually one to three steps are needed. The iteration stops when \(|P(x)|\) is below the error bound of the accurate evaluation. A real root of a polynomial with real coefficients stays exactly on the real axis.
  • Detecting multiple roots. For each root the radius \(r=n\,|P(x)|/|P'(x)|\) is computed, where \(n\) is the degree. A circle with this radius around \(x\) always contains at least one root of \(P\). Roots whose circles overlap are grouped into a cluster. Well separated simple roots have small circles and stay on their own; the \(m\) approximations of an \(m\)-fold root have overlapping circles and form a cluster of size \(m\).
  • Refining a multiple root. An \(m\)-fold root of \(P\) is a simple root of the derivative \(P^{(m-1)}\). Newton's method is therefore applied to \(P^{(m-1)}\), starting from the average of the \(m\) approximations, where it converges quickly and to full accuracy.
  • Verification. The result is only accepted as an \(m\)-fold root if \(P, P', \dots, P^{(m-1)}\) all vanish there to within a few units of rounding error. Otherwise the cluster is treated as close but distinct roots, and each of them is polished on its own. This way two different roots that merely lie close together are not merged, unless they are so close that the polynomial cannot tell them apart within rounding error.

Reading the polishing report

After the solutions, the result area lists one line per root, in the same order X1, X2, ... as the solutions, for example:
    X1=1  |P| 9.0e-12 -> 0.0e+0  radius<=0.0e+0
    X2=2  |P| 2.5e-12 -> 0.0e+0 multiplicity 2, backward error 0.0u
            
  • |P| a -> b is \(|P(x)|\) at the root found by the method, and at the polished root.
  • radius<=r (simple roots) is the radius of a circle around the polished root that contains the exact root of the polynomial. It is usually below one unit in the last place of the root, and 0 when \(P(x)\) is exactly zero, as for integer roots.
  • multiplicity m, backward error w u means the root was verified as an \(m\)-fold root; \(w\) is how far the derivatives are from zero, in units \(u=2^{-53}\) of rounding error.
  • in a cluster of m (not a verified multiple root) means the roots were close together but did not pass the verification, so each was polished as a simple root.
With polishing switched on, the reconstructed polynomial and the error polynomial (shown with Display Iteration trail) are also computed from the polished roots. Verbose mode adds the number of Newton steps used for each root.

Limitations

  • Polishing finds the roots of the polynomial as it is stored in double precision. Coefficients such as 0.1 or 1/3 are already rounded when they are read, and coefficients larger than \(2^{53}\approx 9\cdot10^{15}\) cannot all be stored exactly.
  • For badly conditioned polynomials this matters a lot. In Wilkinson's polynomial \((x-1)(x-2)\cdots(x-20)\), five of the coefficients are rounded when stored, and that alone moves the root at 13 by about \(6\cdot10^{-4}\). Polishing returns the roots of the stored polynomial, which is the best any method can do in double precision.
  • The error bounds are computed in ordinary rounding, so the radius is a very good estimate rather than a mathematical proof.
Uncheck Polish roots to see the roots exactly as the selected method found them.

References: S. Graillat, P. Langlois, N. Louvet: Algorithms for accurate, validated and fast polynomial evaluation, Japan J. Indust. Appl. Math. 26 (2009) 191-214. S. Graillat: Accurate simple zeros of polynomials in floating point arithmetic, Comput. Math. Appl. 56 (2008) 1114-1120. T.J. Dekker: A floating-point technique for extending the available precision, Numer. Math. 18 (1971) 224-242.


Rate this page

Click on the stars below to rate this page

Low
1 star
2 stars
3 stars
4 stars
5 stars
High


Corrections:
4-Nov-2026 vs 1.66. Also available as an app for phones and tablets that works offline. Print and Email are replaced by PDF (view, print, save or share)
24-Oct-2026 Added the Tangent Graeffe method. Jenkins-Traub checked against the original TOMS 493 & TOMS 419, fixed endless loops and a wrong lower bound for complex coefficients
14-Oct-2026 Added an option to polish the roots plus a help section for root polishing
5-Mar-2024 Introduce Autoscaling, no autoscaling in plotting of graph and 2D contour
20-Dec-2023 Added 2D Contour plot
23-Nov-2023 Added 3D Surface plot
30-Oct-2023 Improve the termination criterion for the Durand-Kerner and the Anerth method
22-Oct-2023 Switched to the Plotly librariy for the graphic. The issue with the Plot function has been fixed
12-Jul-2021 Fixed a bug in parsing Polynomial involving non-integer number to the ^ operator
24-Jun-2020 Added Steffensen & Arithmetic Mean Newton root method
6-Jun-2020 Added Chebyshev & Ostrowski Square root method
26-Apr-2020 Added Durand-Kerner and Aberth-Ehrlich method
22-Apr-2020 Fix a bug in the Halley method for multiplicity greater than 1
17-Apr-2020 Fix a bug in the Ostrowski method
16-Mar-2020 Added the Laguerre's and the Eigenvalue methods for finding zeros of Polynomials with either real or complex coefficients
31-Jan-2020 Added the fameous Jenkins-Traub methods for finding zeros of Polynomials with either real or complex coefficients
29-Jan-2020 Fixed an issue where the test for newton convergence produce a wrong result making Newton, Halley & Householder failed for large polynomials
17-Jan-2020 Added 3 extra methods, Halley, Householder 3rd and Ostrowski
1-Nov-2019 GUI redesigned
25-Oct-2018 Fix a bug where the wrong Complex arithmetic libraries was uploaded to the web site.
24-Mar-2014 Fixed several parsing issues involving cascade power e.g. i^2, i^3^2 and cascade power for x e.g. x^2^3 etc. Fixed also an overflow issue when dealing with polynominal with a degree exceeding 174. e.g. x^175+1. Thanks to Kaspii Kaspars & Wei Xu for reporting this.
21-Apr-2011 Email button added, for Emailing the result.
17-Apr-2011 Layout changes and switching to using canvas object for HTML graphic. Now Print also print the Graphic of the Roots, Function Values and Convergence Power
16-Nov-2009 A parsing error was corrected -x^2 was incorrectly parsed as x^2 while -1x^2 was handle correctly
28-Oct-2009 A parsing error was corrected involving proper treatment of the exponent E or e in the expression like1.31E-06
20-Jun-2009 Works now with the Safari Browser
14-Apr-2009 Fixed a bug that allowed overflow in calculation caused by unreasonable step size for large polynomials greater than x^27 resulting in some incorrect roots.
24-Feb-2009 Parsing bug corrected that incorrectly did not recognized an implicit multiplication in complex expression.
01-Jan-2009 Parsing bug corrected that left out the constant term in some situations
23-Oct-2008 Detect a constant as a non polynomial and report an error
05-Sep-2008 Works with Google Chrome
18-Jul-2008 Works with IE7, Firefox 2 & 3 and add polynomial expression as input
30-Oct-2007 Complex coefficients with an implicit value e.g (i) was interpreted as i0 instead of i1
29-July-2007 Now roots point in the graphic display will also be printable
12-July-2007 A bug has been fixed for polynomial with roots of zeros.
07-Dec-2006: A small FireFox 2.0 bug was corrected on Dec 8, 2006. The  problem was that separation of sign and arguments was not done correctly due to a differences in the Regular expression split function. (Thanks to Brian Phelan for making me aware of the problem and providing the fix)