So I am looking at the integral $$ \int_0^{2\pi} \frac{1}{a + \cos\theta} \mathrm{d} \theta$$ for $a > 1$. Evaluating the integral with complex analysis gives us $\frac{2 \pi}{\sqrt{a^2 - 1}} $ but I have failed to reproduce the result using standard substitution.
Here’s what I did: I found the antiderivative first, which is $$\frac{2}{\sqrt{a^2 - 1}} \arctan \left(\sqrt{\frac{a - 1}{a + 1}} \tan\left(\frac{\theta}{2}\right) \right)$$ but substituting in the bounds would give us 0.
I used the standard substitution $t = \tan\left(\frac{\theta}{2}\right) $ to obtain the following result.
EDIT: Plotting the graph shows us that the area is definitely positive, so there’s no way the answer is $0$.
EDIT2: Is it because $2\pi$ corresponds to the second “cycle” so we should $\arctan 0$ to be $\pi$ for our upper bound instead?
The theory about substitution actually states that when you want to use the substitution $t=g(\theta)$:
This statement is not concise but it is rigorous.
You should be able to see your mistake in your treatment.
But this doesn’t mean that it is impossible to use the substitution $t=\tan(\theta/2)$.
Simply break your integral into two parts: $$\int^{\pi^-}_0 \frac{d\theta}{a+\cos\theta} +\int^{2\pi}_{\pi^+} \frac{d\theta}{a+\cos\theta} $$ and then, you are allowed to do the substitution.
Since you have found the antiderivative, things get easier.
Let $F(\theta)$ be the antiderivative you found.
By fundamental theorem of calculus, your integral equals $$\begin{align} &~~~~F(\pi^-)-F(0)+F(2\pi)-F(\pi^+) \\ &=\frac{2}{\sqrt{a^2-1}}\frac{\pi}2-0+0-\frac{2}{\sqrt{a^2-1}}\frac{-\pi}2 \\ &=\color{red}{\frac{2\pi}{\sqrt{a^2-1}}} \end{align} $$
as desired, by noting $\operatorname{arctan}(\infty)=\frac\pi2$ and $\operatorname{arctan}(-\infty)=-\frac\pi2$.