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

What would be the values of this definite Integral?

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

So, I have solved this definite integral using the substitution method, taking $$u=\tan(\theta)$$.

After some simplification, the solution to the definite integral I get is follows:

$$\frac{1}{\sqrt{2}} \, \tan^{-1}\left(\frac{\tan{\theta}}{\sqrt{2}}\right) \Biggr|_{0}^{2\pi}$$

Whenever I am evaluating the above result at the limits of the integration I am getting an answer of $$0$$.

My simplification,

$$=\frac{1}{\sqrt{2}} \, \left[ \tan^{-1}\left(\frac{\tan{2\pi}}{\sqrt{2}}\right) - \tan^{-1}\left(\frac{\tan{0}}{\sqrt{2}}\right) \right]$$ $$=\frac{1}{\sqrt{2}} \, \big[ \tan^{-1}(0) - \tan^{-1}(0) \big]$$ $$=\frac{1}{\sqrt{2}} \, \big[ 0-0]$$ $$=0$$

However, using Mathematical/Integral calculator, the value of this Integral is $$2\pi$$

I am probably doing something very silly, as I can't figure out what I am doing wrong. Any help would be appreciated. Thanks!

• The substitution you made is not bijective. Jul 17, 2020 at 22:34
• @hamam_Abdallah after thinking about it - I don't think the issue was to do with bijectivity, since $u$ substitution doesn't actually require it. What it does require, however, is your substitution be continuous on the domain of integration - and ${u=\tan(x)}$ is not continuous on ${(0,2\pi)}$, and so you have to split up the integral into $4$ separate integrals, just like an improper integral Jul 18, 2020 at 14:50

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 :)

• Thank you for this elaborate answer! This helped a lot overall :D Jul 17, 2020 at 23:05
• Could you please elaborate more why it needs to be injective for the substitution to work? I am getting a vague idea and can't really pin-point it Jul 17, 2020 at 23:09
• Very nice the comment "the u substitution to be injective ..." Jul 17, 2020 at 23:21
• Why not just express $1$ in the original integral as $\sin^2{\theta}+\cos^2{\theta}$? Saves a few steps from your solution.
– Ty.
Jul 18, 2020 at 14:00
• @Riemann'sPointyNose I went into an internet Rabbit hole trying to pinpoint the injectivity issue. Thanks for explaining with an example as well! Jul 18, 2020 at 15:16

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}$$

• Thanks, this helped me clear up lots of things :) Jul 17, 2020 at 23:04

tan(x) is periodic: $$\tan^{-1}(x)$$ is multi valued: $$\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.

• Thank you! This makes sense :D Jul 17, 2020 at 23:05

$$\int_{0}^{2\pi}\frac{1}{\cos^2(\theta)+1}\, d\theta=4\int_{0}^{\pi/2}\frac{1}{\cos^2(\theta)+1}\, d\theta$$ $$=4\int_{0}^{\pi/2}\frac{\sec^2\theta}{1+\sec^2\theta}\, d\theta$$ $$=4\int_{0}^{\pi/2}\frac{\sec^2\theta\ d\theta}{1+\tan^2\theta+1}$$ $$=4\int_{0}^{\pi/2}\frac{d(\tan\theta)}{(\tan\theta)^2+(\sqrt2)^2}$$ $$=4\left[\frac{1}{\sqrt2}\tan^{-1}\left(\frac{\tan\theta}{\sqrt2}\right)\right]_0^{\pi/2}$$ $$=4\left[\frac{1}{\sqrt2}\frac{\pi}{2}-0\right]$$ $$=\color{blue}{\pi\sqrt2}$$

Here is an alternate way with contour integration:

\begin{aligned} J= \int_{0}^{2\pi} \frac{d\theta}{\cos^2 \theta+1} &= \oint_{|z|=1} \frac{\frac{dz}{iz}}{ \left[ \frac{(z+z^{-1})^2}{4}+1 \right]}\\ &= \frac{4}{i}\oint \frac{ z \, dz}{ z^4 + 6 z^2 +1 }\\ \end{aligned}

Take the integral in the positive (counter-clockwise) direction.

There are four roots to the denominator of the integrand: $$z_k \in \left\{ \mp i \sqrt{3 \mp 2\sqrt{2}} \right\}, \quad k=1,\cdots,4$$ The roots inside the circle are $$z_1 = - i \sqrt{3 - 2\sqrt{2}}$$ and $$z_2 = i \sqrt{3 - 2\sqrt{2}}$$.

$$J=2\pi i \cdot \frac{4}{i} \left[ \text{Res}_{z=z_1} \frac{z}{z^4+6z^2+1}+\text{Res}_{z=z_2} \frac{z}{z^4+6z^2+1}\right] = 8\pi \left[\frac{1}{8\sqrt{2}}+ \frac{1}{8\sqrt{2}} \right]=\sqrt{2}\pi.$$

Even easier is to recognize that the substitution $$w=z^2$$ inside the integral leads to

$$J=\frac{4}{i} \oint_{|w|=1} \frac{dw}{w^2+6w+1}$$

We either have to wind around the circle twice in the $$w$$-plane or multiply by $$2$$ so that the constant out in front is again $${4}/{i}$$.

and so

$$J=8\pi \text{ Res}_{z=2\sqrt{2}-3} \, \frac{1}{w^2+6w+1}=8\pi\cdot \frac{1}{4\sqrt{2}}=\sqrt{2}\pi.$$