# Computing $I_{n}=\int \tan(x)^n \mathrm dx$

I'm trying to compute:

$$I_{n}=\int \tan(x)^n \mathrm dx$$

We have:

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

$$I_{n}=\frac{1}{n-1}\tan(x)^{n-1}-I_{n-2}+C$$

Which gives the formulas:

$$\int \tan(x)^{2n} \mathrm dx= \sum_{k=0}^{n-1} \frac{(-1)^k}{2n-(2k+1)}\tan(x)^{2n-(2k+1)}+(-1)^nx+C$$

$$\int \tan(x)^{2n+1} \mathrm dx=\sum_{k=0}^{n-1} \frac{(-1)^k}{2(n-k)}\tan(x)^{2(n-k)}+(-1)^{n+1}\ln(\cos(x))+C$$

I would just like to know if these equalities are correct.

-

@H.R.: I am not sure that your comment is for me but the O.P. detailed rather well his method in the question : he added $I_{n}+I_{n-2}$ to obtain the integral of the derivative of $\tan(x)^{n-1}$ (since $\tan(x)'=1+\tan(x)^2$). After that he used the recurrence to express $I_{2n}$ and $I_{2n+1}$ in function of terms of smaller indices and same parity. Neat work btw (he got my vote), – Raymond Manzoni Mar 17 at 23:05
@RaymondManzoni: In fact, my comment was for the O.P. :) I just don't get that how the recurrence relation $I_{n} + I_{n-2}=\frac{1}{n-1}\tan(x)^{n-1}+C$ is solved? Where the terms $(-1)^n x$ and $(-1)^n \ln \cos x$ come from? They are $I_0$ and $I_1$ I guess! right? – H. R. Mar 18 at 10:52
Yes @H.R. that's it! More exactly it is $(-1)^n I_0$ and $(-1)^n I_1$ (because of the change of sign at every iteration). Once you got $I_{n} + I_{n-2}=\frac{1}{n-1}\tan(x)^{n-1}+C_n$ simply rewrite this for $n\to 2n$ as $I_{2n}= \frac{1}{2n-1}\tan(x)^{2n-1}-I_{2n-2}+C_{2n}$ getting thus(applying the recursion to $I_{2n-2}$) $I_{2n}= \frac{1}{2n-1}\tan(x)^{2n-1}-(\frac{1}{2n-2-1}\tan(x)^{2n-3}-I_{2n-4}+C_{2n-2})+‌​C_{2n}=\cdots$ (stopping at $(-1)^n I_{2n-2n}=(-1)^n I_0$). – Raymond Manzoni Mar 18 at 12:59