Reduction formula for $\int x\tan^n(x)$

So I've been trying to derive a reduction formula for the following integral

$$\int x\tan^n(x)dx$$

I tried to use integration by parts by factoring out a $\tan^2(x)$ and taking the following: $$u=x\tan^{n-2}(x)\implies du=\tan^{n-2}(x)+(n-2)x\tan^{n-3}(x)\sec^2(x)dx\\ dv=\tan^2(x)dx=(\sec^2(x)-1)dx\implies v=\tan(x)-x$$

which then gives

$$I_n=x\tan^{n-1}(x)-x^2\tan^{n-2}(x)-\int\left[\tan^{n-1}(x)+(n-3)x\tan^{n-2}(x)+(n-2)x\tan^n(x)\\-(n-2)x^2\tan^{n-3}(x)\sec^2(x)\right]dx\\ \implies(n-1)I_n=x\tan^{n-1}(x)-x^2\tan^{n-2}(x)-\int\tan^{n-1}(x)dx-(n-3)\int x\tan^{n-2}(x)dx\\+(n-2)\int x^2\tan^{n-3}(x)\sec^2(x)dx$$

The final integral evaluates to

$$\int x^2\tan^{n-3}(x)\sec^2(x)dx=\frac{1}{n-2}\left(x^2\tan^{n-2}(x)-2\int x\tan^{n-2}(x)dx\right)$$

so we end up with

$$(n-1)I_n=x\tan^{n-1}(x)-x^2\tan^{n-2}(x)-\int\tan^{n-1}(x)dx-(n-3)\int x\tan^{n-2}(x)dx\\+x^2\tan^{n-2}(x)-2\int x\tan^{n-2}(x)dx\\ \implies(n-1)I_n=x\tan^{n-1}(x)-\int\tan^{n-1}(x)dx-(n-1)\int x\tan^{n-2}(x)dx\\ =x\tan^{n-1}(x)-\int\tan^{n-1}(x)dx-(n-1)I_{n-2}$$

But this isn't entirely a reduction formula given that I'm unable to deal with the $\int\tan^{n-1}(x)dx$ term. Any help?


Solution 1:

$$\begin{split} I_{n+2} +I_n &= \int x \tan^n (x) (1+\tan^2 x)dx \\ &= \frac 1 {n+1}x \tan^{n+1}(x)-\frac 1 {n+1}\underbrace{\int \tan^n x dx}_{J_n} \end{split}$$ where the last line comes by integrating by parts. Now $$\begin{split} J_{n+2}+J_n &= \int \tan^n (x)(1+\tan^2x) dx\\ &= \frac 1 {n+1}\tan^{n+1}x \end{split}$$ Can you finish?