I am having troubles with the below integral $$\int_{-\infty}^\infty x^2 \cfrac{1}{\sqrt{2\pi}}e^{{-x^2}/{2}} dx$$
In particular, I am getting $2$ instead of $1$ and I guess this is caused by $$\frac{d}{dx} x^2 = 2x$$.
This is what I'm doing: $$\int_{-\infty}^\infty x^2 \cfrac{1}{\sqrt{2\pi}}e^{{-x^2}/{2}} = $$ $$ = \cfrac{1}{\sqrt{2\pi}}\left[ x^2 \frac{e^{-x^2/2}}{-x}\right]^\infty_{-\infty} - \cfrac{1}{\sqrt{2\pi}}\int_{-\infty}^\infty \color{red}2x \frac{e^{-x^2/2}}{-x} dx= $$ $$= \frac{\color{red}2}{\sqrt{2\pi}}\int_{-\infty}^\infty e^{-x^2/2} dx = $$ $$ = \frac{\color{red}2}{\sqrt{2\pi}}\sqrt{2\pi} = \color{red}2$$
I understand that that $2x$ inside the second integral should get simplified, but I can't figure out how. Can you help?
Many thanks!
Taking out the $1/\sqrt{2\pi}$ for convenience, you should be integrating by parts $\int u \; dv = uv - \int v \; du$ with $u = x$, $dv = x e^{-x^2/2}\; dx$, so $du = dx$ and $v = -e^{-x^2/2}$. There is no $2$.