# Mathematica - Count number of zeros of a function in an interval

Let's say I have a function,

F[x_,d_] = Sqrt[(x^2 - 1)^2 + d^2],


and I want to count how many roots (no root, or one root, or two roots etc.) it has in an interval, say, 0 < x < 5 for a given d. I am not interested in the exact value of the root.

For example, it has one root when d = 0, and no root if, say, d = 0.5.

If I use Reduce , and try to count the roots, Mathematica tries to find the exact roots and it is unnecessary slow. There should be an easier way (or maybe built-in function in Mathematica) for this.

This F function is toy model of my real problem, so I cannot play with the algebra of the function. And since function is always positive, I cannot check if the sign of the function changes. But, one thing for sure, function is not differentiable at the roots.

In other words, how can I calculate number of poles of 1/F[x,d] at 0 < x < 5?

• If $d \neq 0$, $x$ can be only complex number. Do you want to count complex roots too? Apr 23, 2015 at 19:23
• @Mahdi no, only real roots. Apr 23, 2015 at 19:31
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! May 11, 2015 at 19:15
• It seems you might not have received the traditional welcome, which I extended to you above. I noticed you haven't accept any answers to your questions. Please consider whether any of the attempts to help you deserve this token reward. May 11, 2015 at 19:16

In the case of polynomials you can use CountRoots when you specify value of d:

CountRoots[Sqrt[(x^2 - 1)^2 + d^2] /. d -> 0, {x, 0, 5}]


1

CountRoots[Sqrt[(x^2 - 1)^2 + d^2] /. d -> 1/2, {x, 0, 5}]


0

It must be noted that CountRoots above counts roots on interval 0 <= x <= 5, not 0 < x < 5.

• Thank you. It works for polynomials. Now I am trying to extend this to my real problem, which is not polynomial. Thank you again. Apr 23, 2015 at 20:20
• @gurluk I fear that's another question altogether... Apr 23, 2015 at 20:36