Calculating the integral $\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}$ I wanted to calculate $$\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}$$
So I solved the indefinite integral first (by substitution):
$$\int\frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}=\frac{1}{b^2}\int\frac{d \theta}{\cos^2\theta \left(\frac{a^2}{b^2} \tan^2\theta+1 \right)} =\left[u=\frac{a}{b}\tan\theta, du=\frac{a}{b\cos^2\theta} d\theta \right ]\\=\frac{1}{b^2}\int\frac{b}{a\left(u^2+1 \right)}du=\frac{1}{ab}\int\frac{du}{u^2+1}=\frac{1}{ab} \arctan \left(\frac{a}{b}\tan\theta \right )+C$$
Then:
$$\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}=\frac{1}{ab} \arctan \left(\frac{a}{b}\tan (2\pi) \right )-\frac{1}{ab} \arctan \left(\frac{a}{b}\tan 0 \right )=0$$
Which is incorrect (the answer should be $2\pi/ab$ for $a>0,b>0$).
On the one hand, the substitution is correct, as well as the indefinite integral itself (according to Wolfram it is indeed $\frac{1}{ab} \arctan \left(\frac{a}{b}\tan\theta \right )$  ), but on the other hand I can see that had I put the limits during the substitution I'd get $\int\limits_{0}^{0} \dots = 0$ because for $\theta = 0 \to u=0$ and for $\theta = 2\pi \to u=0$.
Why is there a problem and how can I get the correct answer?
Edit: Here is Wolfram's answer:


Wolfram is correct because $$\frac{a^2 b^2}{2}\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}$$ is the area of an ellipse (defined by $x=a\cos t , y=b\sin t$), that is $$\frac{a^2 b^2}{2}\int\limits_{0}^{2\pi} \frac{d \theta}{a^2 \sin^2\theta+b^2 \cos^2\theta}=\pi ab$$
 A: The substitution is incorrect : the tangent is not bijective on the interval $[0,2\pi]$. First, you need to restrict yourself to an interval on which the tangent behaves better. Using the $\pi$-periodicity of the function you want to integrate, you can show that:
$$\int_0^{2 \pi} \frac{1}{a \sin^2 (\theta)+b \cos^2 (\theta)} d \theta = 2 \int_{-\pi/2}^{\pi/2} \frac{1}{a \sin^2 (\theta)+b \cos^2 (\theta)} d \theta,$$
and go from there.
Note that this is a good warning about using Wolfram (or any formal computation system) : the formula for the indefinite integral is good, but it holds only on each interval $(k\pi -\pi/2, k\pi+\pi/2)$, which the program does not tell you.
A: Let $a,b>0, $ by symmetry,
$$
\begin{aligned}
\int_{0}^{2 \pi} \frac{d \theta}{a^{2} \sin ^{2} \theta+b^{2} \cos ^{2} \theta} &=4 \int_{0}^{\frac{\pi}{2}} \frac{d \theta}{a^{2} \sin ^{2} \theta+b^{2} \cos ^{2} \theta} \\
&=4 \int_{0}^{\frac{\pi}{2}} \frac{\sec ^{2} \theta d \theta}{a^{2} \tan ^{2} \theta+b^{2}} \\
&=4 \int_{0}^{\infty} \frac{d t}{a^{2} t+b^{2}} \\
&=\frac{4}{a b}\left[\tan ^{-1}\left(\frac{a t}{b}\right)\right]_{0}^{\infty} \\
&=\frac{2 \pi}{a b} 
\end{aligned}
$$
A: A slick way to compute this considers the closed loop $\gamma(t) = a\sin t + i b\cos t$ given by the ellipse and traversed clockwise. Then
$$\frac 1{2\pi i}\int_\gamma\frac{dw}w = -1$$
independently of $a$ and $b$ (this is computing the number of turns the ellipse makes around $w=0$, which is $-1$). On the other hand, computing the line integral explicitly gives
\begin{align}
\frac{1}{2\pi i}\int_0^{2\pi }\frac{\overline{\gamma(t)}}{|\gamma(t)|^2} \gamma'(t)dt &=  \frac{1}{2\pi i}\int_0^{2\pi }\frac{a\sin t - i b\cos t}{a^2\sin^2 t + b^2\cos^2 t} (a\cos t - i b\sin t)dt \\
&=  \frac{1}{2\pi i}\int_0^{2\pi }\frac{(a^2-b^2)\cos t\sin t-iab }{a^2\sin^2 t + b^2\cos^2 t} dt \\
\end{align}
The real part of this integral is
$$ -\frac{ab}{2\pi }\int_0^{2\pi }\frac{dt}{a^2\sin^2 t + b^2\cos^2 t} $$
which gives your result (and the imaginary part is of course zero).
A: You have everything right up to 
$$
\frac{1}{ab}\arctan(\frac{a}{b}\tan(2\pi))-\frac{1}{ab}\arctan(\frac{a}{b}\tan(0))
$$
 Now $\frac{1}{ab}\arctan(\frac{a}{b}\tan(2\pi))$ is $2\pi$ because the $\arctan$ and the $\tan$ are inverse functions.
So we get
$$
\frac{1}{ab}\arctan(\frac{a}{b}\tan(2\pi))-\frac{1}{ab}\arctan(\frac{a}{b}\tan(0))=\frac{1}{ab}2\pi-0
$$
or
$$
\frac{2\pi}{ab}
$$
