<s>[INST] 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.
 [/INST] 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} $$
</s>