Integral over a Gaussian function I want to determine the following integral:
$$\int_\mathbb{R}\left|x-\dfrac{\sigma}{\sigma_{n}}x\right|^{2}e^{\frac{-x^2}{2\sigma^2}}\,dx$$
Thanks for your help!!
 A: Hint. One may write
$$
\begin{align}
\int_\mathbb{R}\left|x-\dfrac{\sigma}{\sigma_{n}}x\right|^2e^{\frac{-x^{2}}{2\sigma^{2}}}\:dx&=\left|1-\dfrac{\sigma}{\sigma_{n}}\right|^2\int_{-\infty}^\infty\,|x|^2\,e^{\frac{-x^{2}}{2\sigma^{2}}}\,dx
\\\\&=2\left|1-\dfrac{\sigma}{\sigma_{n}}\right|^2\int_{0}^\infty\,x^2\,e^{-x^2/2\sigma_{n}^{2}}\,dx
\\\\&=\left|1-\dfrac{\sigma}{\sigma_{n}}\right|^2\cdot \sigma^{3}\sqrt{2\pi}
\end{align}
$$ where we have used the standard gaussian result
$$
\int_{0}^\infty\,x^2\,e^{-x^2/2a^2}\,dx=\sqrt{\frac \pi2}\:a^3,\quad a>0.
$$
A: $$\int_\mathbb{R}|x-\dfrac{\sigma}{\sigma_{n}}x|^{2}e^{\frac{-x^{2}}{2\sigma^{2}}}dx = \left(1-\dfrac{\sigma}{\sigma_{n}}\right)^2\int_\mathbb{R}x^{2}\exp\left(\frac{-x^{2}}{2\sigma^{2}}\right)dx$$
Integrating by parts, one has
$$
\left(1-\dfrac{\sigma}{\sigma_{n}}\right)^2\int_\mathbb{-\infty}^{\infty}x^{2}\exp\left(\frac{-x^{2}}{2\sigma^{2}}\right)dx
=
\left(1-\dfrac{\sigma}{\sigma_{n}}\right)^2(-\sigma^2)\int_\mathbb{-\infty}^{\infty}x\left(\exp\left(\frac{-x^{2}}{2\sigma^{2}}\right)\right)^\prime dx
=
\sigma^2\left(1-\dfrac{\sigma}{\sigma_{n}}\right)^2\int_\mathbb{-\infty}^{\infty}\exp\left(\frac{-x^{2}}{2\sigma^{2}}\right) dx
$$
Last step is to use $$\int_\mathbb{-\infty}^{\infty}\exp\left(\frac{-x^{2}}{2\sigma^{2}}\right) = \sqrt{2\pi\sigma^2}$$
and get
$$\int_\mathbb{R}|x-\dfrac{\sigma}{\sigma_{n}}x|^{2}e^{\frac{-x^{2}}{2\sigma^{2}}}dx = \sqrt{2\pi}\sigma^3\left(1-\dfrac{\sigma}{\sigma_{n}}\right)^2$$
