Evaluate $\int\frac{3\cot3x-\cot x}{\tan x-3\tan3x}\,dx$

To evaluate:

$$I= \int_{ }^{ }\frac{3\cot3x-\cot x}{\tan x-3\tan3x}dx$$

My approach:

Convert $$\cot x$$ and $$\cot 3x$$ terms into $$\tan x$$ and $$\tan3x$$ respectively and use $$\displaystyle \tan3x=\frac{\left(3\tan x-\tan^{3}x\right)}{1-3\tan^{2}x}$$

Further simplification gives me $$\displaystyle I=\int_{ }^{ }\frac{\tan x}{\tan3x}dx$$

How do I proceed further? Any hints are welcome!

Edit:

For anyone wondering how $$\int{\tan x/\tan(3x)}dx=\int{(1-3\tan^2x)/(3-\tan^2x)}dx$$ don't forget $$\displaystyle \tan3x=\frac{\left(3\tan x-\tan^{3}x\right)}{1-3\tan^{2}x}$$

• I think, putting $x=2 \tan^{-1}(t)$ will help. Commented Sep 2, 2021 at 8:20

Lets take $$\int\tan(x)\cot(3x)\, dx$$.

We write $$\tan(x) \cot(3 x)$$ as $$\frac{\sin(4 x)-\sin(2 x)}{\sin(2 x)+\sin(4 x)}$$ which leads to $$\int\frac{\sin(4 x)-\sin(2 x)}{\sin(2 x)+\sin(4 x)}\, dx$$

$$\int\frac{\sin(4 x)}{\sin(2 x)+\sin(4 x)}-\frac{\sin(2 x)}{\sin(2x)+\sin(4 x)}\, dx = \int\frac{2\cos(2x)}{2\cos(2 x)+1}-\frac{\sin(2x)}{\sin(2x)+\sin(4x)}\, dx$$

For the first integrand, we can substitute $$u=2x$$ and $$du=2dx$$ which leads to:

$$\int\frac{\cos(u)}{2\cos(u)+1}\, du-\int\frac{\sin(2x)}{\sin(2x)+\sin(4x)}\, dx$$

Then substituting for the first integrand $$s=\tan\frac{u}{2}$$ and $$ds=\frac{1}{2}du\sec^2\frac{u}{2}$$. Then $$\sin u=\frac{2s}{s^2+1}$$ and $$\cos u=\frac{1-s^2}{s^2+1}$$ and $$du=\frac{2ds}{s^2+1}$$. Then we have:

$$2\int\frac{s^2-1}{s^4-2s^2-3}\, ds-\int\frac{\sin(2x)}{\sin(2x)+\sin(4x)}\, dx= \int\frac{1}{s^2+1}\, ds-\frac{1}{2\sqrt{3}}\int\frac{1}{s+\sqrt{3}}\, ds-\frac{1}{2\sqrt{3}}\int\frac{1}{\sqrt{3}-s}\, ds-\int\frac{\sin(2x)}{\sin(2x)+\sin(4x)}\, dx$$

The integral of $$\frac{1}{s^2+1}$$ is $$\tan^{-1}(s)$$ and for $$\frac{1}{s+\sqrt{3}}$$ we substitute $$p=s+\sqrt{3}$$ and $$dp=ds$$. Since the integral of $$\frac{1}{p}$$ is $$\log p$$ we have:

$$\tan^{-1}(s)-\frac{\log(p)}{2\sqrt{3}}-\frac{1}{2\sqrt{3}}\int\frac{1}{\sqrt{3}-s}\, ds-\int\frac{\sin(2x)}{\sin(2x)+\sin(4x)}\, dx$$

For the integrand $$\frac{1}{\sqrt{3}-s}$$ we substitute $$w=\sqrt{3}-s$$ and $$dw=-ds$$. Thus our resulting integral is so far:

$$\tan^{-1}(s)-\frac{\log(p)}{2\sqrt{3}}+\frac{\log(w)}{2\sqrt{3}}-\int\frac{\sin(2x)}{\sin(2x)+\sin(4x)}\, dx = \tan^{-1}(s)-\frac{\log(p)}{2\sqrt{3}}+\frac{\log(w)}{2\sqrt{3}}-\int\frac{1}{2\cos(2x)+1}\, dx$$

Now lets substitute $$v=2x$$ and $$dv=2dx$$:

$$\tan^{-1}(s)-\frac{\log(p)}{2\sqrt{3}}+\frac{\log(w)}{2\sqrt{3}}-\frac{1}{2}\int\frac{1}{2\cos(v)+1}\, dv$$

After simplifying the second integrand and perform the resubstitutions we obtain:

$$x-\frac{2 \tanh ^{-1}\left(\frac{\tan (x)}{\sqrt{3}}\right)}{\sqrt{3}}$$

$$\int{\tan x/\tan(3x)}dx=\int{(1-3\tan^2x)/(3-\tan^2x)}dx$$

Now, we express the numerator as $$3-\tan^2x-2(1+\tan^2x)$$ so that the integrand becomes $$\int{1-2(\sec^2x/(3-\tan^2x))}dx$$. Now, take $$\tan x=t$$ and simplify to get $$\int{1-2/(3-t^2)}dt$$. Now plugin the formulas to get the answer.

Simplify the integrand ussin the formulae for triple and double angles to get

$$\frac{3 \cot (3 x)-\cot (x)}{\tan (x)-3 \tan (3 x)}=1-\frac{2}{1+2 \cos (2 x)}$$

Now, use $$x=\tan^{-1}(t)$$ and everything becomes simple.

\begin{align*} & \int \frac{3\cot(3x)-\cot x}{\tan x-3\tan(3x)} \, dx \\ &= \int \frac{4\sin^2x-1}{4\sin^2x-3} \, dx \\ &= \int \left(1 + \frac2{4\sin^2x-3}\right) \, dx \\ &= x + 2 \int \frac{\sec^2x}{4\tan^2x-3\sec^2x} \, dx \\ &= x + 2 \int \frac{d\tan x}{\tan^2x-3} \\ &= x + \frac1{\sqrt3} \ln\left|\frac{\sqrt3-\tan x}{\sqrt3+\tan x}\right| + C \end{align*}