1
$\begingroup$

This question already has an answer here:

I would like to solve

Tan[x] == 1/x

Solve[] does not work, suggesting that there is no nice analytical solution for x.

Surprisingly, NSolve[] does not work either:

NSolve[Tan[x] == 1/x, x, Reals]

returns: 'This system cannot be solved with the methods available to NSolve'

However, plotting these two functions shows that they cross around x=0.86: Crossing of Tan(x) and 1/x

This looks suspiciously close to Cos[Pi/6] = 0.866025 but it isn't. It's about 0.86028 (obtained by expanding the graph).

Am I missing something really obvious??

Thanks

$\endgroup$

marked as duplicate by Szabolcs, MarcoB, user9660, RunnyKine, Simon Woods Mar 31 '16 at 19:43

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.

  • $\begingroup$ Use FindRoot. $\endgroup$ – march Mar 31 '16 at 16:46
  • 2
    $\begingroup$ There are infinitely many roots, so you need to specify the one you want: Solve[{Tan[x] == 1/x, 0 < x < 1}, x]. Alternatively, using cotSol[] from this answer: N[cotSol[1], 20]. $\endgroup$ – J. M. is away Mar 31 '16 at 16:48
  • 5
    $\begingroup$ This is a duplicate of Can Reduce really not solve for x here?. However if it doesn't enlighten you, take a look at Roots of a characteristic equation. Can Mathematica solve it?. $\endgroup$ – Artes Mar 31 '16 at 16:51
  • $\begingroup$ As J.M. mentioned, there are many roots. So if you Reduce it to the area between two singularities: Reduce[Tan[x] == 1/x && 0 < x < Pi/2, Reals], you get a pure function x == Root[{-1 + #1 Tan[#1] &, 0.86033358901937976248}] $\endgroup$ – MathX Mar 31 '16 at 16:53
  • $\begingroup$ Duh, yes I see. Tan(x) will cross 1/x lots of places, of course. Thanks all. $\endgroup$ – pdini Mar 31 '16 at 17:01
4
$\begingroup$

Instead of finding the intersection, you can also look for the root of Tan[x]-1/x, which yields the desired result

FindRoot[Tan[x] - 1/x == 0, {x, 0.5}]
{x -> 0.860334}

Greetings, Jürgen

$\endgroup$
  • $\begingroup$ Right! Yes it works, thank you. I had forgotten about that function :) $\endgroup$ – pdini Mar 31 '16 at 16:52
3
$\begingroup$

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}]

enter image description here

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.

$\endgroup$

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