Need help with this integration (solved by Mathematica, but don't understand) I want to calculate this integration
$$\int_0^L e^{-\frac{x^2}{2 a}} \sin \left(\frac{n\pi x}{L}\right)\, dx$$
$a$  $n$  $L$ $\pi$ are all constant.
I tried it in the Mathematica:
Integrate[Sin[(n*Pi*x)/L]*Exp[-x^2/(2*a)], {x, 0, L}]
And got this result:
$$\frac{1}{2} \sqrt{\frac{\pi }{2}} \sqrt{a} e^{-\frac{ a n^2\pi ^2}{2 L^2}} \left(-\text{erfi}\left(\frac{  a n\pi-i L^2}{\sqrt{2} \sqrt{a} L}\right)-\text{erfi}\left(\frac{  a n\pi+i L^2}{\sqrt{2} \sqrt{a} L}\right)+2 \text{erfi}\left(\frac{  \sqrt{a} n \pi}{\sqrt{2} L}\right)\right)$$
Is this solution correct? I don't know how to solve this kind of integration. Could anyone show me the general process of solving this problem?
 A: Using another CAS, I obtained the same "beautiful" result.
However, I think it could be easier to compute the imaginary part of  $$\int_0^L e^{-\frac{x^2}{2 a}} e^{\frac{n\pi x}{L}}\, dx$$ For the antiderivative, you would find $$\int e^{-\frac{x^2}{2 a}} e^{\frac{i n\pi x}{L}}\, dx=-i \sqrt{\frac{a \pi }{2}}  e^{-\frac{\pi ^2 a n^2}{2 L^2}}
   \text{erfi}\left(\frac{\pi  a n+i L x}{ \sqrt{2a} L}\right)$$ which seems to suggest a possible change of variable going back to the definition of the $\text{erfi}$ function which is very closely related to the $\text{erf}$ function.
Added later to this answer
Let us write $$I=\int e^{-\frac{x^2}{2 a}} \sin \left(\frac{n\pi x}{L}\right)\, dx=\frac{1}{2i}\Big(\int e^{-(\frac{x^2}{2 a}-i \frac{n\pi x}{L})} dx-\int e^{-(\frac{x^2}{2 a}+i \frac{n\pi x}{L})} dx\Big)=\frac{1}{2i}(I_1-I_2)$$ Completing the squares, the term appearing as argument of the exponential in the first and second integral write respectively $$-\Big(\frac{\pi ^2 a n^2}{2 L^2}+\frac{(L x-i \pi  a n)^2}{2 a L^2}\Big)$$  $$-\Big(\frac{\pi ^2 a n^2}{2 L^2}+\frac{(L x+i \pi  a n)^2}{2 a L^2}\Big)$$ So $$I_1=e^{-\frac{\pi ^2 a n^2}{2 L^2}} \int e^{-\frac{(L x- i \pi  a n)^2}{2 a L^2}}\, dx$$  $$I_2=e^{-\frac{\pi ^2 a n^2}{2 L^2}} \int e^{-\frac{(L x+ i \pi  a n)^2}{2 a L^2}}\, dx$$ so, for $I_1$ and $I_2$,we can make the respective changes of variable $$X=\frac{(L x- i \pi  a n)}{\sqrt{2 a} L}$$  $$Y=\frac{(L x+ i \pi  a n)}{\sqrt{2 a} L}$$ which give $dx=\sqrt{2 a}~dX$ and  $dy=\sqrt{2 a}~dY$ and so $$I_1=\sqrt{2 a} e^{-\frac{\pi ^2 a n^2}{2 L^2}} \int e^{-X^2}\, dX=\sqrt{\frac{a \pi}{2}} e^{-\frac{\pi ^2 a n^2}{2 L^2}}  \text{erf}(X)$$ $$I_2=\sqrt{2 a} e^{-\frac{\pi ^2 a n^2}{2 L^2}} \int e^{-Y^2}\, dY=\sqrt{\frac{a \pi}{2}} e^{-\frac{\pi ^2 a n^2}{2 L^2}}  \text{erf}(Y)$$ and then the formulas.
