WOLFRAM

CountRoots[f,x]

gives the number of real roots of the univariate function f in x.

CountRoots[f,{x,a,b}]

gives the number of roots between a and b.

Details

  • CountRoots counts roots with multiplicities.
  • The function f can be polynomial, holomorphic or meromorphic etc.
  • Roots that lie exactly at xa or xb are counted.
  • The limits a and b can be complex, in which case the range is taken to be the closed rectangle Re[a]Re[x]Re[b]Im[a]Im[x]Im[b].

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Count the number of polynomial roots between 0 and 10:

Out[1]=1

Count roots of a polynomial in a closed rectangle:

Out[1]=1

Count roots of a real elementary function in a real interval:

Out[1]=1

Count roots of a holomorphic function in a closed rectangle:

Out[1]=1
Out[2]=2

Scope  (20)Survey of the scope of standard use cases

Basic Uses  (8)

Find the number of the real roots:

Out[1]=1

Count roots in a real interval:

Out[1]=1
Out[2]=2

Count roots in a closed rectangle:

Out[1]=1
Out[2]=2

Count roots in a vertical line segment:

Out[1]=1

Count roots in a horizontal line segment:

Out[1]=1

Multiple roots are counted with their multiplicities:

Out[1]=1

For a root of multiplicity , all the derivatives for also vanish:

Out[2]=2

Roots at the endpoints of the interval are included:

Out[1]=1

Roots on the boundary of the rectangle are included:

Out[1]=1

Real Elementary Functions  (6)

Count the real roots of a high-degree polynomial:

Out[1]=1

Find the number of non-negative roots of an algebraic function involving high-degree radicals:

Out[1]=1

Count the non-negative roots of a function involving irrational real powers:

Out[1]=1

Count the real roots of a real exp-log function:

Out[1]=1

Count the real roots of a tame real elementary function:

Out[1]=1

This shows the plot of the function:

Out[2]=2

Count roots of a real elementary function in a bounded interval:

Out[1]=1

This shows the plot of the function:

Out[2]=2

Holomorphic Functions  (3)

Count roots of a holomorphic elementary function in a closed rectangle:

Out[1]=1

Count roots of a holomorphic special function in a closed rectangle:

Out[1]=1

Find the number of roots of an analytic function in a bounded real interval:

Out[1]=1

The double root at zero is counted with multiplicity:

Out[2]=2

Meromorphic Functions  (3)

Count roots of a meromorphic elementary function in a closed rectangle:

Out[1]=1

Visualize roots and poles of the function:

Out[5]=5

Count roots of a meromorphic special function in a closed rectangle:

Out[1]=1

Visualize roots and poles of the function:

Out[2]=2

Find the number of roots of a meromorphic function in a bounded real interval:

Out[1]=1

Plot the function:

Out[2]=2

Applications  (4)Sample problems that can be solved with this function

The number of 17^(th) roots of unity in the closed unit square in the first quadrant:

Out[2]=2

Roots on the boundary are counted:

Out[3]=3

Check that a function has exactly one root in an interval:

Out[1]=1

Use FindRoot to approximate the root:

Out[2]=2

Compute a contour integral of logarithmic derivative of a function using the formula , where is the number of roots for a holomorphic function :

Out[1]=1

Compare with the result of numeric integration:

Out[2]=2

Test stability of equilibria at 0 of linear dynamical systems by counting the roots of the CharacteristicPolynomial[m,x] in the right half-plane:

Use a bound for max absolute value of the roots:

Out[3]=3

Count the roots in the right half-plane:

Out[4]=4

Since all eigenvalues of m have negative real parts, the equilibrium is asymptotically stable:

Out[5]=5

Try a different matrix:

This time there are roots with non-negative real parts:

Out[7]=7

The equilibrium is not asymptotically stable:

Out[8]=8

Properties & Relations  (5)Properties of the function, and connections to other functions

The number of complex roots of a polynomial is equal to its degree:

This gives a bound on absolute values of roots of a polynomial:

Out[3]=3

The polynomial indeed has 10 roots within the Cauchy bounded region:

Out[4]=4

The number of real roots of a polynomial with nonzero terms is at most :

Out[1]=1

This polynomial has the maximal possible number of real roots:

Out[2]=2

Use Reduce to find polynomial roots:

Count roots:

Out[2]=2

Find roots:

Out[3]=3

Use RootIntervals to find isolating intervals for roots:

Count the real roots:

Out[2]=2

Isolate the real roots:

Out[3]=3

Use NumberFieldSignature to count the real roots and the pairs of complex roots of a polynomial:

Out[2]=2
Out[3]=3

Possible Issues  (1)Common pitfalls and unexpected behavior

Roots at the endpoints of the interval are included:

Out[1]=1

Neat Examples  (1)Surprising or curious use cases

Count the roots of a meromorphic function:

Out[1]=1

Plot the roots as spikes:

Out[2]=2
Wolfram Research (2007), CountRoots, Wolfram Language function, https://reference.wolfram.com/language/ref/CountRoots.html (updated 2017).
Wolfram Research (2007), CountRoots, Wolfram Language function, https://reference.wolfram.com/language/ref/CountRoots.html (updated 2017).

Text

Wolfram Research (2007), CountRoots, Wolfram Language function, https://reference.wolfram.com/language/ref/CountRoots.html (updated 2017).

Wolfram Research (2007), CountRoots, Wolfram Language function, https://reference.wolfram.com/language/ref/CountRoots.html (updated 2017).

CMS

Wolfram Language. 2007. "CountRoots." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/CountRoots.html.

Wolfram Language. 2007. "CountRoots." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/CountRoots.html.

APA

Wolfram Language. (2007). CountRoots. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CountRoots.html

Wolfram Language. (2007). CountRoots. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CountRoots.html

BibTeX

@misc{reference.wolfram_2025_countroots, author="Wolfram Research", title="{CountRoots}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/CountRoots.html}", note=[Accessed: 09-May-2025 ]}

@misc{reference.wolfram_2025_countroots, author="Wolfram Research", title="{CountRoots}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/CountRoots.html}", note=[Accessed: 09-May-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_countroots, organization={Wolfram Research}, title={CountRoots}, year={2017}, url={https://reference.wolfram.com/language/ref/CountRoots.html}, note=[Accessed: 09-May-2025 ]}

@online{reference.wolfram_2025_countroots, organization={Wolfram Research}, title={CountRoots}, year={2017}, url={https://reference.wolfram.com/language/ref/CountRoots.html}, note=[Accessed: 09-May-2025 ]}