Improper multiple integals involving inner porduct I'm trying to evaluate the following expression: 
$$\int_{\mathbb{R}^n} \langle x,a \rangle^2e^{-\frac{1}{2}\lvert x \rvert^2}dx$$
where $x,a \in \mathbb{R}^n$.

I tried reduction to the case where $a$ is an element of the "natural basis" in $\mathbb{R}^n$ but I can't see how to go from there.
 A: Note : I know I forgot the square in this proof, but please read the proof without the square, as the approach with the square is very analogous.
Write $\langle x,a \rangle = a_1 x_1 + \cdots + a_n x_n$ and $|x|^2 = x_1^2 + \cdots + x_n^2$, so that $e^{-|x|^2} = e^{-x_1^2} \cdots e^{-x_n^2}$. By Fubini's theorem, your integral becomes
$$
\int_{\mathbb R^n}\langle x,a \rangle e^{-|x|^2} dx = \sum_{i=1}^n  \int_{\mathbb R^n} a_i x_i e^{-|x|^2} \, dx_i = \sum_{i=1}^n a_i \left( \int_{\mathbb R} e^{-x^2} \, dx \right)^{n-1} \int_{\mathbb R} x_i e^{-x_i^2} \, dx_i. 
$$
The power to the $n-1$ appears because the integrals $\int_{\mathbb R} e^{-x_j^2} \, dx_j$ do not depend on $j$ for $1 \le j \le n$, $j \neq i$. These integrals correspond to the error function, so their value is well-known ; by integration by parts you can do the last integral with respect to $x_i$. I leave the computations to you.
Now if you want to do it with the square, do the exact same trick ; the integrals appearing are just a bit more complicated (the integral of $x^2 e^{-x^2}$ instead of $xe^{-x^2}$) and there are a bit more terms. Fubini's theorem splits the product of variables appearing when you square the inner product. The error function $\mathrm{erf}(x_i)$ should show up in the computations.
Added : As suggested by the OP in the comments, let $T : \mathbb R^n \to \mathbb R^n$ be an orthogonal transformation with $Ta = (|a|,0,\cdots,0)$. Since the Jacobian is $1$, letting $u = Tx$, because $|u| = |Tx| = |x|$, this integral becomes
$$
\int_{\mathbb R^n} \langle x,a \rangle^2 e^{-|x|^2} \, dx = \int_{\mathbb R^n} \langle Tx,Ta \rangle^2 e^{-|x|^2} \, dx = \int_{\mathbb R^n} \langle u,Ta \rangle^2 e^{-|u|^2} \, du = \int_{\mathbb R^n} |a|^2u_1^2 e^{-|u|^2} \, du. 
$$
Now use Fubini and complete as in my other example. But as I said above, you still need to integrate $\int_{\mathbb R} x^2 e^{-x^2} \, dx$ in any case ; with the hint you only spare yourself the sums and re-arranging.
Hope that helps,
A: This is really simple. In $\mathbb R^2$ you have
\begin{align*}
\int \langle x,a\rangle^2e^{-|x|^2/2}\,dx
&= \int\int (a_1^2x_1^2+2a_1a_2x_1x_2+a_2^2x_2^2)e^{-x_1^2/2}e^{-x_2^2/2}\,dx_1\,dx_2\\
&= a_1^2\int\left(\int x_1^2e^{-x_1^2/2}\,dx_1\right)e^{-x_2^2/2}\,dx_2 + 2a_1a_2\left(\int xe^{-x^2/2}\,dx\right)^2\\
&\qquad\qquad+ a_2^2\int x_2^2e^{-x_2^2/2}\left(\int e^{-x_1^2/2}\,dx_1\right)dx_2\\
&= 2\pi a_1^2 + 0 + 2\pi a_2^2 = 2\pi(a_1^2+a_2^2)
\end{align*}
In higher dimensions you can proceed analogously. In the end, your result should be $(2\pi)^{n/2}\|a\|_2^2$.
