Dreadfort said:
I am doing BSc Physics and this is in my first year Mathematics module. The topic for this assignment was Improper Integrals
I will outline another approach that does not use contour integration, but is still way beyond most Calculus II material.
A fairly standard trick when dealing with such problems is to introduce a function like
$$F(k) = \int_{-\infty}^{\infty} \frac{\cos(kx)}{x^2+1} \, dx, $$
and to note that you want to compute ##F(1)##. We can try differentiating twice ##F(k)## under the integral sign to get back something close to ##F(k)## again, and so get a differential equation to solve. However, in this case, differentiating once or twice leads to a divergent integral, so to get around that we introduce an additional "mollifier" to ensure convergence. In other words, we look at
$$G_a(k) = \int_{-\infty}^{\infty} \frac{e^{-ax^2} \cos(kx)}{x^2+1} \, dx,$$
where ##a>0##. At the very end we will take the limit ##a \to 0.##
Differentiating twice wrt ##k## under the integral sign gives
$$\frac{d^2}{dk^2} G_a(k) = -\int_{-\infty}^{\infty} \frac{e^{-ax^2} \, x^2 \,\cos(kx)}{x^2+1} \, dx.$$
Writing ##-x^2 = -(x^2+1) +1## in the numerator, we obtain
$$\frac{d^2}{dk^2} G_a(k) = - \int_{-\infty}^{\infty} \cos(kx) e^{-a x^2} \, dx + G_a(k)$$
The integral on the right is do-able, so the differential equation for ##G_a## is
$$\frac{d^2}{dk^2} G_a(k) = G_a(k) - \frac{\sqrt{\pi}}{\sqrt{a}} e^{-k^2/(4a)}.$$
This can be solved in terms of the so-called "error function", and the resulting solution contains two constants of integration. If we note that ##G_a(k) = G_a(-k)## for all real ##k##, we can express one of the integration constants in terms of the other. Now we also have that ##G_a(0) = \int e^{-ax^2}/(x^2+1) \, dx,## which is do-able in terms of the error function. We can also get ##G_a(0)## by putting ##k=0## in the solution of the differential equation. Equating these two quantities fixes the constant of integration, so now we have an explicit formula for ##G_a(k)## that no longer contains any unknown constants. Now we can put ##k=1## and then take the limit as ##a \to 0##.
We get the answer ##\pi/e##, which could have been obtained in 3 or 4 lines of easy work using contour integration!