Lets take $f(x)=\ln{x}$ and $g(x)=\tan{x}$

When $f(x)=g(x)$ that is $\ln{x}=\tan{x}$, we see that the graph is like:

ln(x) = tan(x)

Hence we see that there are infinitely many solutions to $x$ but the two graphs do not coincide (like while solving "$x=x$"!)

The solutions as given by WolframAlpha were like :

Sol. to ln(x)=tan(x)

So i decided to use Newton's method to solve this but due to having infinitely many solutions, all solutions given by that method were close to the approximations given by WolframAlpha but were not as accurate.

$x_{n+1} = x_{n} - \dfrac{\ln{x_{n}}-\tan{x_{n}}}{{\dfrac{1}{x_{n}}}-\sec^2{x_{n}}}$

giving us x = 4.02 , 7.31 , ... (and hence not correct)

So is there any other way to solve these system of equations? Maybe using Lambert-W or maybe it does have some simple solution which I'm missing?

Please help, Thanks!

  • $\begingroup$ Using Newton's method depends on (a) your starting point and (b) how many iterations you use. For the $k$th solution, try starting at say $x_0=(k+\frac14)\pi$ and look say at $x_4$. I get about $4.095461606, 7.390369575, 10.59483666, 13.77289661, 16.93905539$ and you can always take more iterations $\endgroup$
    – Henry
    May 11, 2015 at 6:54
  • $\begingroup$ @Henry I know that it depends upon starting point but Newton's method is for finding approximates using guesses...but can we have a concrete solutions to this? $\endgroup$
    – NeilRoy
    May 11, 2015 at 6:55
  • $\begingroup$ There are many more problems which have solutions than problems which have solutions in a closed form using standard functions. What do you mean by concrete? $\endgroup$
    – Henry
    May 11, 2015 at 7:07
  • $\begingroup$ @Henry I mean a solution without using newton's method and hence giving us accurate answer and no approximations. $\endgroup$
    – NeilRoy
    May 11, 2015 at 7:09
  • 1
    $\begingroup$ Even if you use special functions you will need a method to approximate the special function at the points of interest, which will have error just like Newton's method. There will be no "exact" answer available. $\endgroup$ May 13, 2015 at 5:56

4 Answers 4



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)}$$


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$.


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$.

  • $\begingroup$ Can we do it without newton's method? BTW thanks for this method! $\endgroup$
    – NeilRoy
    May 11, 2015 at 7:45
  • 2
    $\begingroup$ When you have in the equation a mixture of polynomial, trigonometric, exponential functions, only numerical methods and Newton is the simplest. Remember that $x=\cos(x)$ cannot be solved analytically. And, you are very welcome. $\endgroup$ May 11, 2015 at 7:54
  • 1
    $\begingroup$ You are welcome ! I thought about it this morning during breakfast and I tried. Simple, quite nice and accurate solutions. Using that as the starting point, I bet that Newton would converge very fast (one or two iterations). $\endgroup$ May 13, 2015 at 6:07

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


$$ \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}, $$


$$ 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). $$

  • $\begingroup$ I stole the first bit of this from my answer here. $\endgroup$ May 22, 2015 at 15:25

If you do not mind a contour integral expression for your roots, one can use the Delves-Lyness scheme to represent your roots:

$$x_{\ast}=\frac1{2\pi i}\oint_\gamma \frac{z f^\prime(z)}{f(z)}\,\mathrm dz$$

where $f(x_{\ast})=0$ and $\gamma$ is any anticlockwise contour encircling the desired root and has no poles of $f(x)$ within.

In particular, borrowing Claude's strategy of reformulating the equation as $\log x\cos x-\sin x=0$ and localizing the roots around $x=\pi\left(k+\frac12\right)$, we can use the contour $\gamma=\pi\left(k+\frac12\right)+\frac{\pi}{4}\exp(it)$ to evaluate the Delves-Lyness contour integral. A realization in Mathematica for finding the first $10$ roots goes like this:

Table[Re[NIntegrate[Exp[I t] (Cos[#] - # Log[#] Sin[#] - # Cos[#])/
                    (Log[#] Cos[#] - Sin[#]) &[π (k + 1/2) + π Exp[I t]/4],
                    {t, 0, 2 π},
                    Method -> {"Trapezoidal", "SymbolicProcessing" -> 0}]/8],
      {k, 10}]

   {4.095461605910074, 7.390369571112949, 10.59483666075098, 13.772896612324644,
    16.93905539111342, 20.098667030734298, 23.254225459730314, 26.40706896072724,
    29.55798827765332, 32.70748457864333}

and these can be polished further with Newton-Raphson or some other iterative method if need be.


A simple recursion for $x^{(n)}$ (the $n-$th root, around $n \pi$, with $n\ge 1$) is

$$ x^{(n)}_{i+1}= \tan^{-1} \left( \log x^{(n)}_{i} \right) + n \pi$$

starting with $x^{(n)}_{0}= n \pi$.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .