Evaluating $\int_{0}^{2\pi}\frac{1}{\cos^2(\theta)+1}\, d\theta$

You can find the solution below, and afterwards an explanation as of why your $u$ substitution did not work.

An alternative way is to write

$${\int_{0}^{2\pi}\frac{1}{1+\cos^2(x)} dx=4\int_{0}^{\frac{\pi}{2}}\frac{1}{1+\cos^2(x)}dx}$$

$${=4\int_{0}^{\frac{\pi}{2}}\frac{\sin^2(x) + \cos^2(x)}{1+\cos^2(x)}dx}$$

Now, dividing the top and bottom by ${\cos^2(x)}$ gives

$${4\int_{0}^{\frac{\pi}{2}}\frac{\tan^2(x) + 1}{\sec^2(x) + 1} dx}$$

Now using some more trig identities, we get

$${=4\int_{0}^{\frac{\pi}{2}}\frac{\sec^2(x)}{\tan^2(x) + 2}dx}$$

$${=4\int_{0}^{\infty}\frac{1}{2+u^2}du}$$

Now, solving that integral

$${\int_{0}^{\infty}\frac{1}{2+u^2}du=\frac{1}{2}\int_{0}^{\infty}\frac{1}{1+\left(\frac{u}{\sqrt{2}}\right)^2}du}$$

Now do ${k=\frac{u}{\sqrt{2}}}$:

$${=\frac{1}{\sqrt{2}}\int_{0}^{\infty}\frac{1}{1+k^2}dk=\frac{\pi}{2\sqrt{2}}}$$

So putting the whole thing together:

$${=4\times \frac{\pi}{2\sqrt{2}}=\sqrt{2}\pi}$$

Which is the correct answer :)

EDIT: After some reconsideration, I don't believe the issue in your original ${u}$ substitution was really to do with injectivity at all. In fact injectivity is not a strict requirement for $u$ substitution. If we redo all the steps we just did, but don't change the domain of integration, you end up with

$${\int_{0}^{2\pi}\frac{1}{1+\cos^2(x)}dx=\int_{0}^{2\pi}\frac{\sec^2(x)}{\tan^2(x) + 2}dx}$$

You may be tempted to once again do ${u=\tan(x)}$ (which is essentially what you did I believe?) but one requirement for $u$ substitution that is very clearly needed is for $u$ to be continuous on the domain of integration (it needs to be differentiable, and so clearly continuity is a requirement!). ${u=\tan(x)}$ certainly is not continuous on ${(0,2\pi)}$, and so you really end up with an improper integral of sorts. Now, we could split up the integral instead, just as we would with any old improper integral:

$${\int_{0}^{2\pi}\frac{\sec^2(x)}{\tan^2(x) + 2}dx=\int_{0}^{\frac{\pi}{2}}\frac{\sec^2(x)}{\tan^2(x) + 2}dx + \int_{\frac{\pi}{2}}^{\frac{3\pi}{2}}\frac{\sec^2(x)}{\tan^2(x) + 2}dx + \int_{\frac{3\pi}{2}}^{2\pi}\frac{\sec^2(x)}{\tan^2(x) + 2}dx}$$

And now it is legitimate to do ${u=\tan(x)}$, since ${\tan(x)}$ will be differentiable and continuous on these domains (well, technically not at the endpoints - but you take a limit, as per the definition of how we deal with improper integrals). Indeed you will get the answer of ${\sqrt{2}\pi}$ if you evaluate this expression.

So if this was the issue, why did people jump to injectivity / bijectivity? Well there are some instances where this is (indirectly) the problem. An example:

$${\int_{0}^{2\pi}xdx}$$

Clearly the answer to this is ${2\pi^2}$. Now do the substitution ${u=\sin(x)}$ - our endpoints become ${\int_{0}^{0}}$... does this mean the integral is $0$? NO! Recall $u$ substitution only says that

$${\int_{a}^{b}f(\phi(x))\phi'(x)dx = \int_{\phi(a)}^{\phi(b)}f(u)du}$$

If you actually attempt to write ${\int_{0}^{2\pi}xdx}$ to match the form of the lefthand side so we can legit utilise $u$ substitution you will end up using some nasty ${\arcsin}$ rubbish - but the key point to take away is that the ${\arcsin}$ function only gives back principle values. ${\arcsin(\sin(x))}$ does not necessarily equal to ${x}$ for all ${x \in \mathbb{R}}$!. So in actuality you end up having a piecewise function to represent ${x}$, so you are forced to split the integral up. So in this case injectivity is in fact a sort of "requirement" indirectly (unless you split up the integral).

I hope this helped explain a bit better :)


hint

Begin by the substitution $$t=\theta-\pi$$ it becomes $$\int_{-\pi}^{\pi}\frac{dt}{\cos^2(t)+1}=$$ $$2\int_0^\pi\frac{dt}{\cos^2(t)+1}$$

because the integrand is an even function. By the same, if you put $$v=t-\frac{\pi}{2}$$ it gives $$4\int_0^\frac{\pi}{2}\frac{dv}{2-\cos^2(v)}$$

and now, make the change $$u=\tan(v)$$ to get $$4\int_0^{+\infty}\frac{du}{2(1+u^2)-1}=\pi\sqrt{2}$$


tan(x) is periodic:

enter image description here

$\tan^{-1}(x)$ is multi valued:

enter image description here

$\tan(x) = \tan(x+ k\pi) = y$

$\tan^{-1}(y) = x + k\pi$

Wolfram gives $\sqrt{2} \pi$ for the integral.

$\tan^{-1}\left(\frac{\tan{2\pi}}{\sqrt{2}}\right) = \tan^{-1}(0) = 0 + k\pi = 2\pi$ in this case.