2
$\begingroup$

I wish to find ALL the roots of the following equation $ x \tan(ax) - c = 0$ within a range, where a and c are constants I control.

I've been using FindRoot[x*Tan[a*x] - c, {x, 5}], but that obviously gives me only the root closest to 5 (for example).

I wish to store all the roots within a range (say, -10 to 10), within an array, and use it later.

I'm pretty new to Mathematica, and thanks in advance!

$\endgroup$

marked as duplicate by bbgodfrey, Mr.Wizard Feb 5 '15 at 7:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2
$\begingroup$
f[x_] := x*Tan[a*x] - c
With[{a = 1, c = 5}, Plot[{f[x]}, {x, -10, 10}]]

enter image description here

red = Reduce[f[x] == 0 && -10 < x < 10, {x}, Reals] // N

x == -9.62956 || x == -6.57833 || x == -3.6436 || x == -1.07687 || x == 1.07687 || x == 3.6436 || x == 6.57833 || x == 9.62956

And if you want to continue using the results,

xVals = Apply[List, red[[All, 2]], {0, 1}]

{-9.62956, -6.57833, -3.6436, -1.07687, 1.07687, 3.6436, 6.57833, 9.62956}

yVals = Array[0 &, 8]

{0, 0, 0, 0, 0, 0, 0, 0}

points = Transpose[{xVals, yVals}]

{{-9.62956, 0}, {-6.57833, 0}, {-3.6436, 0}, {-1.07687, 0}, {1.07687, 0}, {3.6436, 0}, {6.57833, 0}, {9.62956, 0}}

With[{a = 1, c = 5}, 
Plot[{f[x]}, {x, -10, 10}, 
Epilog -> {Red, PointSize[Large], Point@points}]]

enter image description here

$\endgroup$
1
$\begingroup$

Choose a range of starting points and then delete duplicate roots:

a = 1;
c = .5; 
DeleteDuplicatesBy[(x /. 
   Table[FindRoot[x*Tan[a*x] - c, {x, i}], {i, -5, 5, .2}] ), 
 Round[#, .1] &]

enter image description here

As an error message points out, the Jacobian at $x = 0$ is singular, and thus the source of the incorrect point at $x = 0$. Likewise the discontinuities in Tan[] will not be found.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.