Solving $\ln{x}=\tan{x}$ with infinitely many solutions

Hint

The problem is better conditioned if, instead, you look for the roots of $$h(x)=\log(x)\cos(x)-\sin(x)=0$$ and the convergence of Newton method is much faster.

For example, using $x_0=4$, the iterates are : $4.09701$, $4.09546$ which is the solution for six significant digits. Using $x_0=7$, the iterates are : $7.42088$, $7.39041$, $7.39037$.

Using this transform, you will find easily the $k^{th}$ root starting at $x_0=(2k+1)\frac \pi 2$. The first iterate will just be $$x_1=\pi \left(k+\frac{1}{2}\right)-\frac{1}{\log \left(\pi \left(k+\frac{1}{2}\right)\right)}$$

Edit

What is interesting is to look at the value of the solution $x_k$ as a function of $k$. A totally empirical model leads to the following approximation $$x_k=(2k+1)\frac \pi 2-\Big(0.0962696 +\frac{0.489665}{k^{0.409352}}\Big)$$ For example, the estimate of the $10^{th}$ root is $32.6997$ while the solution is $32.7075$; the estimate of the $50^{th}$ root is $158.455$ while the solution is $158.456$.

Just for comparison wtih the results from Wolfram Alpha, the five first roots are estimated as $4.12645,7.38901,10.5870,13.7633,16.9291$.

Edit

There is another way to generate nice approximate values of the $k^{th}$ solution. The idea is to build for function $h(x)$ its simplest Pade approximant around $\theta_k=(2k+1)\frac \pi 2$ and to compute the value of $x$ which cancels the numerator. This leads to the simple approximation $$x_k\approx\theta_k \left(1-\frac{2 \log (\theta_k)}{\theta_k \left(2 \log ^2(\theta_ k)+1\right)-2}\right)$$ Just for comparison wtih the results from Wolfram Alpha, the five first roots are estimated as $4.13630,7.40792,10.6062,13.7814,16.9459$. The $10^{th}$ root is estimated as $32.7113$ and the $50^{th}$ root is estimated as $158.457$.

We could still improve using a Pade[1,2] approximant which would lead to $$x_k\approx \theta_k\Big(1 -\frac{3 \left(\theta_k +2 \theta_k \log ^2(\theta_k )-2\right)}{\theta_k \log (\theta_k ) \left(5 \theta_k +6 \theta_k \log ^2(\theta_k )-12\right)-3}\Big)$$ Just for comparison wtih the results from Wolfram Alpha, the five first roots are estimated as $4.09189,7.38912,10.5942,13.7725,16.9387$. The $10^{th}$ root is estimated as $32.7074$ and the $50^{th}$ root is estimated as $158.455$.


In each interval $\left(\pi n - \frac{\pi}{2}, \pi n + \frac{\pi}{2}\right)$ there is exactly one solution $x_n$ (i.e. $\tan x_n = \ln x_n$), and, when $n$ is large, it appears that $x_n$ is approximately $\pi n + \frac{\pi}{2}$. Let's show this.

Since $\tan$ is $\pi$-periodic we have

$$\tan\left(\pi n + \frac{\pi}{2} - x_n\right) = \tan\left(\frac{\pi}{2} - x_n\right)$$ $$\hspace{2.4 cm} = \frac{1}{\tan x_n}$$ $$\hspace{2.6 cm} = \frac{1}{\ln x_n} \to 0$$

as $n \to \infty$, where the second-to-last equality follows from the identites $$\sin\left(\frac{\pi}{2} - \theta\right) = \cos \theta,$$ $$\cos\left(\frac{\pi}{2} - \theta\right) = \sin \theta.$$

Since $-\frac{\pi}{2} < \pi n + \frac{\pi}{2} - x_n < \frac{\pi}{2}$ and since $\tan$ is continuous in this interval we have $\pi n + \frac{\pi}{2} - x_n \to 0$ as $n \to \infty$.

So, we know that

$$ x_n = \pi n + \frac{\pi}{2} + o(1). $$

Let's get an estimate for the error term. If we set $w_n = \left(\pi n + \frac{\pi}{2}\right)^{-1}$ and $z_n = w_n^{-1} - x_n$ then

$$ \tan x_n = \frac{1}{\tan z_n} $$

by the above calculation and

$$ \ln x_n = \ln w_n^{-1} + \ln(1+w_n z_n), $$

so the equation $\tan x_n = \ln x_n$ becomes

$$ \frac{1}{\tan z_n} = \ln w_n^{-1} + \ln(1+w_n z_n). \tag{$*$} $$

Now $w_n,z_n \to 0$ as $n \to \infty$, so

$$ \frac{1}{\tan z_n} \sim \frac{1}{z_n} $$

and

$$ \ln w_n^{-1} + \ln(1+w_n z_n) \sim \ln w_n^{-1} $$

as $n \to \infty$. Thus, from $(*)$,

$$ \frac{1}{z_n} \sim \ln w_n^{-1}, $$

or

$$ z_n \sim \frac{1}{\ln w_n^{-1}} = \frac{1}{\ln(\pi n + \pi/2)}. $$

By definition of $z_n$ we therefore get the asymptotic

$$ x_n = \pi n + \frac{\pi}{2} - \frac{1}{\ln(\pi n + \pi/2)} + o\left(\frac{1}{\ln n}\right). $$