Help in two improper integrals For a physics problem, I need to evaluate two integrals:
$$I_n=\int_{0}^{\infty} f(x) dx=\int_{0}^{\infty} \frac{x^2 \sin^2x}{(n^2\pi^2-x^2)^2} dx,$$ and
$$J_n=\int_{0}^{\infty} \frac{x^2 \cos^2x}{((n+1/2)^2\pi^2-x^2)^2} dx, n=1,2,3..$$
At Mathematica the value of these integral turns out to be $\pi/4$ which is independent of $n$.
$I_n$ has got a pole of order 2 at $x=n\pi$ and when I calculate the residue at $x=n \pi$  is zero. But on the other hand I find that  $\lim_{x \to n\pi} f(x)=0,$  so $x=n\pi$ may not be a pole of $f(x)$. I face the same problem in the case of $J_n$. Also $I_0=\pi/2$ is a standard integral. In any case, I want to evaluate both $I_n$ and $J_n$.  Please help me.
 A: Let is use $$\int_{n\pi}^{\infty} \frac{\sin^2 t}{t^2} dt=\frac{\pi}{2}-\text{Ei}(2n \pi)$$
Then
$$I_n=\int_{0}^{\infty} \frac{x^2 \sin^2 x}{x^2-n^2\pi^2} dx$$
$$=\frac{1}{4}\int_{0}^{\infty} dx \left(\frac{\sin^2 x}{(x-n\pi)^2}+\frac{\sin^2 x}{(x+n\pi)^2}+\frac{\sin^2 x}{4n\pi(x-n\pi)}-\frac{\sin^2 x}{4n\pi(x+n\pi)}\right)$$
$$I_n=\frac{1}{4}[\pi/2-\text{Ei}(2n\pi)+\pi/2+\text{Ei}(2n\pi)]+\int_{-n\pi}^{n\pi} \frac{\sin^2 t}{t}dt=\frac{\pi}{4} $$
Similarly
$$J_n=\int_{0}^{\infty} \frac{x^2 \cos^2 x}{x^2-m^2\pi^2} dx, m=n+1/2$$
$$=\frac{1}{4}\int_{0}^{\infty} dx \left(\frac{\cos^2 x}{(x-m\pi)^2}+\frac{\cos^2 x}{(x+m\pi)^2}+\frac{\cos^2 x}{4m\pi(x-m\pi)}-\frac{\cos^2 x}{4m\pi(x+m\pi)}\right)$$
$$I_n=\frac{1}{4}[\pi/2-\text{Ei}(2m\pi)+\pi/2+\text{Ei}(2m\pi)]+\int_{-m\pi}^{m\pi} \frac{\sin^2 t}{t}dt=\frac{\pi}{4} $$
A: $I_n=\int_{0}^{\infty} \frac{x^2 \sin^2x}{(n^2\pi^2-x^2)^2} dx$. Integrating by part end expanding integration to the whole axis (the integrand is even) we get
$I_n=-\frac{1}{2}\int_{0}^{\infty} \frac{\sin^2x+x\sin2x}{(n^2\pi^2-x^2)} dx=-\frac{1}{4}\int_{-\infty}^{\infty} \frac{x\sin2x}{(n^2\pi^2-x^2)}dx-\frac{1}{8}\int_{-\infty}^{\infty} \frac{1-\cos2x}{(n^2\pi^2-x^2)}dx=I_1+I_2$.
Then we choose the closed contour $C$ in upper half of the complex plane:

To close the contour, we added two small half-circles $C_1$ and $C_2$ of radius $r$ - around $x=-n\pi$ and $x=n\pi$ $(r\to0)$, and a big circle of radius $R$ ($R\to\infty$). The required integral $I_n$ is equal to the principal value of the integral along the axis. Then,  $\sin2x=Im \exp(i2x)$ and $\cos2x=Re\exp(2ix)$.
The integral over the closed contour $\oint_C=0$ (no singular points inside the contour), therefore$I_n+I_{C1}+I_{C2}+I_R=0$. It is easy to evaluate that $I_R\to0$ at $R\to\infty$ (using Jordan's lemma),
so $I_n=-I_{C1}-I_{C2}$
$I_1=-\frac{1}{4}Im\int_{-\infty}^{\infty} \frac{xe^{2ix}}{(n^2\pi^2-x^2)}dx=Im(-I_{C1}-I_{C2})=\frac{1}{4}Im\left((-\pi{i})[\frac{-\pi{n}\exp(-2\pi{in})}{2\pi{n}}+\frac{\pi{n}\exp(2\pi{in})}{-2\pi{n}}]\right)$
$$I_1=\frac{\pi}{4}$$
Making similar calculations it is easy to show that $I_2=0$
Finally, $$I_n=I_1+I_2=\frac{\pi}{4}$$
$J_n$ can be evaluated in the same way.
