<s>[INST] Can't solve $\int_{0}^{\pi} \frac{x}{1 + \cos^2x} dx$ I tried this :-
Let $$I =\int_{0}^{\pi}\frac{x}{1 + \cos^2x}dx\tag{1}$$
then $$I = \int_{0}^{\pi}\frac{\pi-x}{1 + \cos^2(\pi-x)}dx= \int_{0}^{\pi}\frac{\pi-x}{1 + \cos^2x}dx\tag{2}$$
Adding (1) and (2), we get
$$
2I = \int_{0}^\pi\frac{\pi}{1 + \cos^2x}dx\\
= \pi\int_{0}^{\pi}\frac{1}{1 + \frac{1}{\sec^2x}}dx\\
= \pi\int_{0}^{\pi}\frac{\sec^2x}{\sec^2x + 1}dx\\
= \pi\int_{0}^{\pi}\frac{\sec^2x}{2 + \tan^2x}dx
$$
Let $\tan x = u$, then $du = \sec^2x dx$
Then,
$$\int \frac{\sec^2x}{2+\tan^2x}dx = \int \frac{du}{2 + u^2} = \frac{1}{\sqrt{2}}\tan^{-1}\frac{u}{\sqrt{2}}+c = \frac{1}{\sqrt{2}}\tan^{-1}\frac{\tan x}{\sqrt{2}}+c
$$
Therefore,
$$
2I = \frac{\pi}{\sqrt{2}}\left[\tan^{-1}\frac{\tan x}{\sqrt{2}}\right]_0^\pi\\
\Rightarrow I = \frac{\pi}{2\sqrt{2}}\left[\tan^{-1}\frac{\tan x}{\sqrt{2}}\right]_0^\pi\\= \frac{π}{2\sqrt{2}}\left[\tan^{-1}\frac{\tan \pi}{\sqrt{2}} - \tan^{-1}\frac{\tan 0}{\sqrt{2}}\right]\\=\frac{\pi}{2\sqrt{2}}[\tan^{-1}0 - \tan^{-1}0] \\= 0\\$$
But the answer given in the book is $\frac{\pi^2}{2\sqrt{2}}$
What am I doing wrong ?
 [/INST] Hint For a slightly more theoretically demanding solution you can start out like this:

Let $$h(x) = f(x)\cdot g(x)\\ f(x) = x\\ g(x) = \frac{1}{1+\cos(x)^2}$$
Now we seek $$\int_0^{\pi}h(x)dx$$
But with Fourier analysis we know:
$$\hat h(0) = \int h(x)dx$$
And furthermore we know $${\hat {(f\cdot g)}} = \hat f * \hat g$$
Your integral can be viewed as DC component (frequency 0 component of Fourier transform) of product between on interval $x\in [0,\pi]$. 
These functions $\hat f, \hat g$ should be raaather nice to describe in Fourier domain and we can leave the rest as an exercise for the curious student.
</s>