NRoots[lhs==rhs,var]
yields a disjunction of equations which represent numerical approximations to the roots of a polynomial equation.
NRoots
NRoots[lhs==rhs,var]
yields a disjunction of equations which represent numerical approximations to the roots of a polynomial equation.
Details and Options
- NRoots gives several identical equations when roots with multiplicity greater than one occur.
- NRoots has the following options:
-
MaxIterations Automatic maximum number of iterations to use Method Automatic method to use PrecisionGoal Automatic the precision sought StepMonitor None expression to evaluate at each step - Possible settings for the Method option include: "Aberth", "CompanionMatrix", and "JenkinsTraub".
Examples
open all close allBasic Examples (1)
Scope (1)
Find the numerical roots of a polynomial with only real roots:
NRoots[x ^ 3 - 5x ^ 2 + 6x - 1 == 0, x]Find the numerical roots of a polynomial with real and complex roots:
NRoots[x ^ 3 - x ^ 2 - x - 1 == 0, x]Find the numerical roots of a polynomial with multiple roots:
NRoots[(x - 1)(x - 2)^2(x - 3)^3 == 0, x]Options (5)
Method (3)
Use the "Aberth" method, which simultaneously approximates all the roots of a univariate polynomial and converges cubically in general (but linearly at multiple zeros):
Block[{it = 0}, NRoots[z ^ 5 - 10z ^ 4 + 43z ^ 3 - 104z ^ 2 + 150z - 100 == 0, z, Method -> "Aberth", StepMonitor :> Print["Iteration: ", ++it, ", roots:", Chop[N[z]]]]]Use the "CompanionMatrix" method:
Block[{it = 0}, NRoots[z ^ 5 - 10z ^ 4 + 43z ^ 3 - 104z ^ 2 + 150z - 100 == 0, z, Method -> "CompanionMatrix", StepMonitor :> Print["Iteration: ", ++it, ", roots:", Chop[N[z]]]]]Use the "JenkinsTraub" method, which is a standard fast iterative globally convergent root-finding algorithm for polynomials:
Block[{it = 0}, NRoots[z ^ 5 - 10z ^ 4 + 43z ^ 3 - 104z ^ 2 + 150z - 100 == 0, z, Method -> "JenkinsTraub", StepMonitor :> Print["Iteration: ", ++it, ", roots:", Chop[N[z]]]]]PrecisionGoal (1)
Specifying PrecisionGoal can improve the precision of the roots returned:
poly = -6 + 3 x - 6 x^2 + 12 x^3 - 4 x^4 + 7 x^5 - 7 x^6 + x^7 + 5 x^9 - 2 x^10 - 4 x^11 - 12 x^12 + 2 x^13 + 7 x^14 + 12 x^15 - 7 x^16 - 10 x^17 - 4 x^18 + 3 x^19 + 9 x^20 - 7 x^21 - 8 x^23 + 14 x^24 - 3 x^25 + 9 x^26 + 2 x^27 - 3 x^28 - 10 x^29 - 2 x^30 - 6 x^31 + x^32 + 10 x^33 - 3 x^34 + x^35 + 7 x^36 - 7 x^37 + 7 x^38 - 12 x^39 - 5 x^40 + 8 x^41 + 6 x^42 + 10 x^43 - 8 x^44 - 8 x^45 - 7 x^46 - 3 x^47 + 9 x^48 + x^49 + 6 x^50 + 6 x^51 - 2 x^52 - 3 x^53 - 10 x^54 - 2 x^55 + 3 x^56 + 5 x^57 + 2 x^58 - x^59 - x^60 - x^61 - x^62 - x^63 + x^64 + 2 x^65 + 2 x^66 - x^67 - 2 x^68 - x^69 + x^71;Select[x /. {ToRules[NRoots[poly == 0, x]]}, Positive]Select[x /. {ToRules[NRoots[poly == 0, x, PrecisionGoal -> 20]]}, Positive]Select[x /. {ToRules[NRoots[poly == 0, x, PrecisionGoal -> 50]]}, Positive]Compare with the digits from an exact computation:
N[Reduce[poly == 0, x, PositiveReals], 50]StepMonitor (1)
Monitor the root-finding steps:
Block[{it = 0}, NRoots[Expand[(x - 1)(x - 2)^2(x - 3)^3] == 0, x, StepMonitor :> Print["Iteration: ", ++it, ", roots: ", Chop[N[x]]]]]
Using a different Method gives different convergence:
Block[{it = 0}, NRoots[Expand[(x - 1)(x - 2)^2(x - 3)^3] == 0, x, Method -> "CompanionMatrix", StepMonitor :> Print["Iteration: ", ++it, ", roots:", Chop[N[x]]]]]Applications (1)
Visualize the asymptotic rate of growth of the terms in the "look and say sequence," which is given by the positive real root of the following polynomial:
poly = -6 + 3 x - 6 x^2 + 12 x^3 - 4 x^4 + 7 x^5 - 7 x^6 + x^7 + 5 x^9 - 2 x^10 - 4 x^11 - 12 x^12 + 2 x^13 + 7 x^14 + 12 x^15 - 7 x^16 - 10 x^17 - 4 x^18 + 3 x^19 + 9 x^20 - 7 x^21 - 8 x^23 + 14 x^24 - 3 x^25 + 9 x^26 + 2 x^27 - 3 x^28 - 10 x^29 - 2 x^30 - 6 x^31 + x^32 + 10 x^33 - 3 x^34 + x^35 + 7 x^36 - 7 x^37 + 7 x^38 - 12 x^39 - 5 x^40 + 8 x^41 + 6 x^42 + 10 x^43 - 8 x^44 - 8 x^45 - 7 x^46 - 3 x^47 + 9 x^48 + x^49 + 6 x^50 + 6 x^51 - 2 x^52 - 3 x^53 - 10 x^54 - 2 x^55 + 3 x^56 + 5 x^57 + 2 x^58 - x^59 - x^60 - x^61 - x^62 - x^63 + x^64 + 2 x^65 + 2 x^66 - x^67 - 2 x^68 - x^69 + x^71;nroots = x /. {ToRules[NRoots[poly == 0, x]]}Visualize the roots in the complex plane, highlighting the unique positive one:
ListPlot[ReIm /@ nroots, PlotStyle -> {PointSize[.02], Blue}, AspectRatio -> Automatic, Epilog -> {PointSize[.03], Red, Point[Flatten[ReIm /@ Select[nroots, Positive]]]}]Properties & Relations (7)
Return numerical roots using NRoots:
NRoots[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, x]{ToRules[%]}Compare with the numericization of roots returned by Roots:
Roots[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, x]N[%]Compare with the numerical roots returned by NSolve:
NSolve[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, x]Compare with the numericization of roots returned by Solve:
Solve[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, x]N[%]Compare with the numericization of roots returned by Reduce:
Reduce[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, x]N[%]Compare with a single numerical root returned by FindRoot:
FindRoot[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, {x, -.6}]Compare with the numericization of a single root returned by FindInstance:
FindInstance[1 + 2 x + 3 x ^ 2 + 4 x ^ 3 == 0, x]N[%]Possible Issues (3)
NRoots returns unevaluated when called on a non-polynomial equation:
NRoots[Exp[x](x - 1) == Exp[-x](x + 1), x]NRoots can return small imaginary parts for polynomials with real roots:
poly = Expand[Product[(x - k) ^ k, {k, 4}]];NRoots[poly, x]Use Chop to remove them:
Chop[%]Increasing MaxIterations does not necessarily give more accurate results:
wilkinson1 = Expand[Product[x - k, {k, 20}]]NRoots[wilkinson1 == 0, x, Method -> "JenkinsTraub"]NRoots[wilkinson1 == 0, x, Method -> "JenkinsTraub", MaxIterations -> 10 ^ 6]In such cases, increasing the PrecisionGoal can sometimes give more precise results:
NRoots[wilkinson1 == 0, x, Method -> "JenkinsTraub", MaxIterations -> 10 ^ 6, PrecisionGoal -> 20]Interactive Examples (1)
Interactively plot the real roots of a cubic polynomial:
Manipulate[Block[{poly = a x ^ 3 + b x ^ 2 + c x + d}, Plot[poly, {x, -2, 2}, Epilog -> {AbsolutePointSize[5], Red, Point[Thread[{Select[x /. {ToRules[NRoots[poly == 0, x]]}, Im[#] == 0&], 0}]]}]], {{a, -1}, -1, 1}, {{b, -.64}, -1, 1}, {{c, .72}, -1, 1}, {{d, .24}, -1, 1}]See Also
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2007 (6.0)
Text
Wolfram Research (1988), NRoots, Wolfram Language function, https://reference.wolfram.com/language/ref/NRoots.html (updated 2007).
CMS
Wolfram Language. 1988. "NRoots." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/NRoots.html.
APA
Wolfram Language. (1988). NRoots. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NRoots.html
BibTeX
@misc{reference.wolfram_2026_nroots, author="Wolfram Research", title="{NRoots}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/NRoots.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_nroots, organization={Wolfram Research}, title={NRoots}, year={2007}, url={https://reference.wolfram.com/language/ref/NRoots.html}, note=[Accessed: 13-June-2026]}