3

How do i Count[] the number of roots in the Domain and printout the intervals in x containing these roots.

Given the function

f[x_] := (1/x) Sin[ x]

and the Domain

{x, -2.5 Pi, 2.5 Pi}
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Nabil
  • 513
  • 3
  • 16

2 Answers2

6

I'll address only the root counting portion. In this paper, Delves and Lyness present a method based on contour integration for counting all the complex roots of a function within a given contour. In your specific case, it goes like this:

Round[Chop[NIntegrate[f'[z]/f[z], {z, -5 π/2, -5 π I/2, 5 π/2, 5 π I/2, -5 π/2}]/(2 π I)]]
   4

where I used an anticlockwise square contour with two corners on the endpoints of interest. Luckily, the function is known to have only real roots, so the count obtained is accurate. For more complicated functions, a different contour might be needed.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
3

You can use FindInstance to Find several instances:

FindInstance[f[x] == 0 && -2.5 Pi < x < 2.5 Pi, x, 4]

{{x->-6.28319},{x->-3.14159},{x->-6.28319},{x->3.14159}}

or some others:

Reduce[f[x] == 0 && -2.5 Pi < x < 2.5 Pi, x]

x==-6.28319||x==-3.14159||x==3.14159||x==6.28319

using Length, as suggested by @Michael E2

Length[%]

4

sol = NSolve[{f[x] == 0, -2.5 Pi < x < 2.5 Pi}, x]

{{x->-6.28319},{x->-3.14159},{x->3.14159},{x->6.28319}}

Length[%]

4

points = {x, f[x]} /. sol // Chop

{{-6.28319, 0}, {-3.14159, 0}, {3.14159, 0}, {6.28319, 0}}

Plot[f[x], {x, -2.5 Pi, 2.5 Pi}, Epilog -> {Red, PointSize[Large], Point@points}]

enter image description here

You can show the Intervals like so:

NumberLinePlot[f[x] == 0, {x, -2.5 Pi, 2.5 Pi}]

enter image description here