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 ?
 A: As you have found ever the dicontinuing of $\tan$ is the problem, so you can solve it with your method after this substitution
$$\int_{0}^{\pi}\dfrac{1}{1+\cos^2x}\ dx=2\int_{0}^{\pi/2}\dfrac{1}{1+\sin^2t}\ dt= \color{blue}{\dfrac{\pi}{\sqrt{2}}}$$
where we use the substitution $x=t+\dfrac{\pi}{2}$. Other way is complex integration, with $2x=t$ we have
$$
\begin{align}
\int_{0}^{\pi}\dfrac{1}{1+\cos^2x}\ dx&= 
\int_{0}^{2\pi}\dfrac{1}{3+\cos t}\ dt \\
&=\int_{|z|=1}\dfrac{1}{3+\frac12(z+\frac1z)}\dfrac{dz}{iz} \\
&= -2i\int_{|z|=1}\dfrac{1}{(z+3-2\sqrt{2})(z+3+2\sqrt{2})}dz \\
&= \color{blue}{\dfrac{\pi}{\sqrt{2}}}
\end{align}
$$
A: As $\tan x$ is discontinuous at $\dfrac\pi2,$ let's fold the integral in the first quadrant
$$I=\int_0^{2a}f(x)\ dx=\int_0^af(x)\ dx+\int_a^{2a}f(x)\ dx$$
Now set $2a-x=y$ in $\displaystyle J=\int_a^{2a}f(x)\ dx$
to find $\displaystyle J=\int_a^0f(2a-y)\ (-dy)=\int_0^af(2a-y)\ dy=\int_0^af(2a-x)\ dx$
$$\displaystyle I=\int_0^{2a}f(x)\ dx=\begin{cases} 2\displaystyle\int_0^af(x)\ dx &\mbox{if } f(2a-x)=f(x) \\ 
0& \mbox{if } f(2a-x)=-f(x)\end{cases} $$
Here $2a=\pi,f(x)=\dfrac1{1+\cos^2x}$
A: 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.
