interesting integral involving powers of tan in the denominator I ran across this integration problem that has an interesting pattern.
$$\int_{0}^{(n-1)\pi}\frac{1}{\tan^{n}(x)+1}dx=\frac{(n-1)\pi}{2}$$
I evaluated increasing values of n up to n=10, and the result is always one half the upper limit of integration. 
Why is this?. That is, how could we show it. I graphed it and as n gets larger, the graph resembles rectangles of equal size stacked up along the x-axis. 
Thanks. 
 A: If $n$ is even,
then $\dfrac{1}{\tan^n x + 1} = \dfrac{\cos^n x}{\sin^n x + \cos^n x}$ is periodic with period $\pi$.
Also for $x \in [0, \pi/2]$ we have that for $t = x + \pi/2$ that $\dfrac{\cos^n t}{\sin^n t + \cos^n t} = \dfrac{\sin^n x}{\sin^n x + \cos^n x}$ 
And so 
$\int_{0}^{\pi} \dfrac{1}{\tan^n x + 1} = \int_{0}^{\pi/2} \dfrac{\cos^n x}{\sin^n x + \cos^n x} + \int_{0}^{\pi/2} \dfrac{\sin^n x}{\sin^n x + \cos^n x} = \pi/2$.
A: For every odd $n$, the integral is not defined. For every even $n$, the integral equals what you say. To show this, first note that since the function you integrate has period $\pi$, it is enough to show that $I_k=\pi/2$, where
$$
I_k=\int_0^\pi\frac{\mathrm{d}x}{\tan(x)^{2k}+1}.
$$
To compute $I_k$, use the change of variable $t=\tan(x)$, hence $\mathrm{d}t=(1+t^2)\mathrm{d}x$ and
$$
I_k=\int_{-\infty}^{+\infty}\frac{\mathrm{d}t}{(t^{2k}+1)(t^2+1)}=2\int_0^{+\infty}\frac{\mathrm{d}t}{(t^{2k}+1)(t^2+1)}.
$$
Decompose the last integral into an integral from $0$ to $1$ and an integral from $1$ to $+\infty$, to which one can apply the change of variable $s=1/t$. This yields
$$
I_k=2\int_0^{1}\frac{\mathrm{d}t}{(t^{2k}+1)(t^2+1)}+2\int_0^{1}\frac{s^{2k}\mathrm{d}s}{(1+s^{2k})(1+s^2)}.
$$
Finally,
$$
I_k=2\int_0^{1}\frac{\mathrm{d}t}{t^2+1}=2[\arctan(t)]_0^1=\pi/2.
$$
