NSolve
is primarily meant for polynomial equations, or equations that can be transformed into a polynomial.
For equations like this, we usually have two choices:
FindRoot
to find a single solution numerically, based on a starting guess
Reduce
can often find an "exact" solution (in some sense), but to succeed it typically requires specifying an interval in which to look.
This equation has an infinite number of real solutions.
Plot[{Tan[x], 1/x}, {x, -3 Pi, 3 Pi}]
Use FindRoot
to find one:
FindRoot[Tan[x] == 1/x, {x, 1}]
(* {x -> 0.860334} *)
Use Reduce
to find all solutions in a given interval:
Reduce[Tan[x] == 1/x && -2 Pi < x < 2 Pi, x, Reals]
(* x == Root[{-1 + #1 Tan[#1] &, -3.4256184594817281465}] ||
x == Root[{-1 + #1 Tan[#1] &, -0.86033358901937976248}] ||
x == Root[{-1 + #1 Tan[#1] &, 0.86033358901937976248}] ||
x == Root[{-1 + #1 Tan[#1] &, 3.4256184594817281465}] *)
Note that Reduce[Tan[x] == 1/x, x, Reals]
does not return any solution. Specifying the interval was essential.
This latter solution is exact in the following sense:
When Reduce
succeeds, it is guaranteed to find all solutions in the given interval
The Root
objects, while based on a numerical approximation, represent an exact solution, and can be used as any other exact number in Mathematica (e.g. can be computed to arbitrary precision).
This interesting and useful feature of Reduce
is discussed in this Wolfram Blog post.
FindRoot
. $\endgroup$Solve[{Tan[x] == 1/x, 0 < x < 1}, x]
. Alternatively, usingcotSol[]
from this answer:N[cotSol[1], 20]
. $\endgroup$Reduce
it to the area between two singularities:Reduce[Tan[x] == 1/x && 0 < x < Pi/2, Reals]
, you get a pure functionx == Root[{-1 + #1 Tan[#1] &, 0.86033358901937976248}]
$\endgroup$