# Numerical solution to x = tan (x)

I needed to find, using the bisection method, the first positive value that satisfy $x = \tan(x)$. So I went to Scilab, I wrote the bisection method and I got $1.5707903$. But after some reasoning I came to the conclusion that this value is wrong:

1. $\tan(1.5707903) \approx 1.6x10^5$. Not even close to $1.5707903$.
2. Forget for a moment the above. $x = \tan(x)$ is actually to find fixed points of $f(x) = \tan(x)$; $(x, f(x))$ must be in the line $y = x$. Here is the plot:

In $(0, \frac{3}{2}\pi)$ I can only see a fixed point to the right of $x = 4$, therefore $1.5707903$ is wrong.

Here comes the interesting part. If you go to Wolfram Alpha and type $x = \tan(x)$, you will see $1.5708$ in the Plot section:

However there is no $1.5708$ in the Numerical solutions section. Wolfram Alpha found $0, \pm 4.49340945790906, \ldots$.

But if you type $\tan(x) = x$, you will not see $1.5708$ in the Plot section!:

To summarize:

1. Is $4.49340945790906$ the first positive value that satisfy $x = \tan(x)$?
2. Do you know why Wolfram Alpha is showing $1.5708$ as a solution when you type $x = \tan(x)$ but not when you type $\tan(x) = x$?

Thanks.

-
related/possible duplicate –  Parth Kohli Feb 16 '13 at 14:32
(1) $\tan x$ maps $(-\pi/2,\pi/2)$ bijectively onto $\mathbb{R}$. (2) Moreover, $\tan$ is periodic with period $\pi$. From (1) and (2) it follows that the $x$ we are looking for is in $(\pi/2,3\pi/2)$. –  AD. Feb 16 '13 at 14:36
BTW bisection is not very fast at all, I would suggest you tried with Newton-Raphson with a starting point like $\pi$. –  AD. Feb 16 '13 at 14:37
@AD.: I'm interested in your reasoning but I'm not able to follow it. Could you please explain how from (1) and (2) you concluded that the $x$ we are looking for is in $(\pi/2,3\pi/2)$? –  David Robert Jones Feb 16 '13 at 15:08
Bisection would definitively work depending on the choose of starting points they need both to belong in $I_n = (-\pi/2,\pi/2)+\pi\cdot n$ and surround the fixed point. –  AD. Feb 16 '13 at 15:23

The reason you are getting this "solution" is because the bisection method assumes the function is continuous in the range, which it's not. Since the function at both sides of $x=\pi/2$ is $\pm \infty$, the bisection method will always converge to this "solution".

-
Nor is continuous at $[\pi/2,3\pi/2]$ however the solution is there. –  David Robert Jones Feb 16 '13 at 15:29
@DavidRobertJones - it's continuous on the open interval. –  nbubis Feb 16 '13 at 15:33

As you see from the plot of $\tan x$, you're intercepting the asymptote, which is not really the desired behavior. Bisection is not the best method to use.

However, if you're required to use bisection, then instead note that $\tan x = \frac{\sin x}{\cos x}$, so, for relevant values of $x$,

$$x = \tan x \implies x\cos x - \sin x = 0$$

The latter function is continuous, and you should get the desired solution of $x \approx 4.49$.

-
I like your idea. Now I'm wondering: What function would you use as $g(x)$ if you're required to use fixed-point iteration method? –  David Robert Jones Feb 16 '13 at 22:28
@DavidRobertJones Offhand, I suspect $\sin^{-1}(x\cos x) = x$ should work, as long you start the iteration in $(0,2\pi)$. –  Arkamis Feb 16 '13 at 23:38
I'm not sure since $\sin^{-1}(x\cos x)$ has no fixed points in the interval. Also don't forget the conditions for convergence. –  David Robert Jones Feb 17 '13 at 21:15
@DavidRobertJones It should. I'm not sure if it meets the convergence criteria, but the fixed point should be in $(0,2\pi)$, if the solution is in the interval. –  Arkamis Feb 18 '13 at 3:34
Ah, I know what's wrong... I'm failing to consider the domain of arcsin properly. Maybe substitution exploiting the periodicity of cos will work... I don't know :) –  Arkamis Feb 18 '13 at 3:46