Definite Integral $x^{n} e^{x^2} $ I want to find an expression for the integral
\begin{align*}
\int x^{n} e^{x^2}~dx \quad or \int_{a}^{b} x^{n} e^{x^2}~dx.
\end{align*}
I tried this way:
\begin{align*}
\int x^{n} e^{x^2}~dx=\frac{1}{2}\int x^{n-1} 2x e^{x^2}~dx
\end{align*}
using integration by parts
\begin{align*}
\frac{1}{2}\int x^{n-1} (2x) e^{x^2}~dx=\frac{1}{2}x^{n-1}e^{x^2}-\frac{1}{2}\int(n-1) x^{n-2} e^{x^2}~dx
\end{align*}
This will continue ..... Is there any better way to deal with this integral?
 A: If $n$ is odd, then $n=2k+1$, and by letting $u=x^2$, we get
$$\int x^ne^{x^2}\ dx=\frac12\int(x^2)^ke^{x^2}(2x\ dx)=\frac12\int u^ke^u\ du$$
Now consider the additional parameter:
$$\int e^{ut}\ du=\frac{e^{ut}}t$$
Differentiate $k$ times with respect to $t$ and you'll end up with
$$\int u^ke^u\ du=\frac{d^k}{dt^k}\frac{e^{x^2t}}t\bigg|_{t=1}$$
Thus,
$$\int x^ne^{x^2}\ dx=\frac12\frac{d^k}{dt^k}\frac{e^{ut}}t\bigg|_{t=1}+c$$

If $n$ is even, then $n=2k$,
$$\int x^ne^{x^2}\ dx=\int x^{2k}e^{x^2}\ dx$$
By integration by parts with $u=x^{2k-1}$ and $dv=xe^{x^2}\ dx$, we get
$$\int x^{2k}e^{x^2}\ dx=\frac12x^{2k-1}e^{x^2}-\frac{2k-1}2\int x^{2k-2}e^{x^2}\ dx$$
Which gives the reduction formula
$$I_k=\int x^{2k}e^{x^2}\ dx\\I_k=\frac12x^{2k-1}e^{x^2}-\frac{2k-1}2I_{k-1}$$
and with the imaginary error function,
$$I_0=\frac{\sqrt\pi}2\operatorname{erfi}(x)+c$$
$$I_{1/2}=\frac12e^{x^2}+c$$
(note that you can use $I_{1/2}$ to cover the odd case instead of using differentiation under the integral sign as I did above)
