The following integral can be obtained using the online Wolfram integrator:

$$\int \frac{dx}{1+\cos^2 x} = \frac{\tan^{-1}(\frac{\tan x}{\sqrt{2}})}{\sqrt{2}}$$

Now assume we are performing this integration between $0$ and $2\pi$. Hence the result of the integration is zero.

On the other hand when looking at the integrand, $\displaystyle \frac{1}{1+\cos^2 x}$, we see that it is a periodic function that is never negative. The fact that it is never negative guarantees that the result of the integration will never be zero (i.e., intuitively there is a positive area under the curve).

What is going on here?


Solution 1:

(This is an expansion of my earlier comment.)

Consider the function

$$f_c(x)=\frac{x}{\sqrt 2}-\frac1{\sqrt 2}\arctan\left(\frac{\sin\,2x}{3+2\sqrt{2}+\cos\,2x}\right)$$

You can check that the derivative of $f_c(x)$ is $\dfrac1{1+\cos^2 x}$. The relevance of this function is that $f_c(x)$, unlike the function $f(x)=\dfrac1{\sqrt 2}\arctan\left(\dfrac{\tan\,x}{\sqrt 2}\right)$ given in the OP, has no discontinuities within the integration interval $[0,2\pi]$:

plot of two antiderivatives

Thus,

$$\int_0^{2\pi}\frac{\mathrm dx}{1+\cos^2 x}=\left.\frac{x}{\sqrt 2}-\frac1{\sqrt 2}\arctan\left(\frac{\sin\,2x}{3+2\sqrt{2}+\cos\,2x}\right)\right|_0^{2\pi}=\pi\sqrt 2$$

One wonders how the two functions $f(x)$ and $f_c(x)$ could look so different and yet have the same derivative. A plot of $f_c(x)-f(x)$ shows the difference:

f_c(x)-f(x)

Here, we see that the two functions differ not by a constant, but by a piecewise constant function (i.e., a step function). In fact, the Fundamental Theorem of the Calculus can be stated a bit more generally than is usual in textbooks. To quote Oleksandr Pavlyk's blog entry on this subject,

Every calculus student knows that antiderivatives can contain an arbitrary additive constant. But in fact, there’s more arbitrariness than that: one can add different constants on different parts of the interval.

As already mentioned in the previous answers, the trouble lies in the use of the Weierstrass substitution; the source of the problem, simply put, is that the substitution function used happens to be discontinuous within the interval of integration. Thus, to properly evaluate definite integrals of rational functions of sine and cosine, one has to be careful in using the Weierstrass substitution, and must pay attention to the behavior near the singularities.

Jeffrey and Rich, in their paper, discuss methods for computer algebra systems to cope with this particular weakness of the Weierstrass substitution.


For the sake of completeness, here's a general formula for an antiderivative of $\dfrac1{p+q\cos^2 x}$ that is continuous over the real line:

$$\int\frac{\mathrm dx}{p+q\cos^2 x}=\frac1{\sqrt{p(p+q)}}\left(x-\arctan\left(\frac{q\sin\,2x}{2p+q+2\sqrt{p(p+q)}+q\cos\,2x}\right)\right)$$

Solution 2:

If $\tan(y)=a\tan(x)$, then $\tan(y-x)=\frac{(a-1)\tan(x)}{1+a\tan^2(x)}$, and therefore, $$ y=x+\tan^{-1}\left(\frac{(a-1)\tan(x)}{1+a\tan^2(x)}\right)\tag{1} $$ Since $\left|\frac{(a-1)\tan(x)}{1+a\tan^2(x)}\right|\le\frac{\left|a-1\right|}{2\sqrt{a}}$, $(1)$ is a nice continuous function of $x$.

In this question, $a=\frac1{\sqrt2}$, so we get $$ \int\frac{\mathrm{d}x}{1+\cos^2(x)}=\frac{x-\tan^{-1}\left(\frac{(\sqrt2-1)\tan(x)}{\sqrt2+\tan^2(x)}\right)}{\sqrt2}\tag{2} $$

Solution 3:

An unusual substitution, the "$\tan(z/2)$"substitution, is being done here. You must take a careful look at what you are integrating. Here is a reference on this substitution.

Solution 4:

Quite simple: the $\arctan$ function is multivalued, so you have to add the appropriate multiples of $\pi$ to the function to get at the right result; i.e., $\sqrt{2}\pi$