Series expansion to evaluate $\int_{0}^{\infty}{e^{-ax^2}\cos(3x)\,dx}$ I know $$\int_{0}^{\infty}{e^{-ax^2}\cos(3x)\,dx}$$
can be computed via $\cos(3x)=\Re({e^{3ix})}$, but when trying to do it via a Taylor series I ran into problems. I started by expanding one of the two functions and then swapping the order of the integral and sum (which I hope is justified in this case) :
$$\begin{align}&=\int_{0}^{\infty}{\sum_{k=0}^{\infty}{\frac{(-ax^2)^k}{k!}}\cos(3x)\, dx}\\&=\sum_{k=0}^{\infty}{\frac{(-a)^k}{k!}\int_{0}^{\infty}{x^{2k}\cos(3x)}\, dx}\end{align}$$
How can I continue here (maybe I should have expanded $\cos(3x)$ with a series instead)? The remaining integral seems like it isn't convergent...
 A: Turns out the cosine expansion instead was what was needed (thanks @Plutoro) :
$$\begin{align}I&=\int_{0}^{\infty}{e^{-ax^2}\sum_{k=0}^{\infty}{\frac{(-9)^kx^{2k}}{(2k)!}}\, dx}\\&=\sum_{k=0}^{\infty}{\frac{(-9)^k}{(2k)!}\int_{0}^{\infty}{x^{2k}e^{-ax^2}\, dx}}\end{align}$$
Then if (taking the derivative, integrating by parts and then solving the ODE)
$$\begin{align}f(a)&=\int_{0}^{\infty}{x^{2k}e^{-ax^2}\, dx}\\f'(a)&=-\int_{0}^{\infty}{x^{2k+1}xe^{-ax^2}\, dx}\\&=-\left(\left[-\frac{x^{2k+1}}{2a}e^{-ax^2}\right]_{0}^{\infty} + \frac{2k+1}{2a}\int_{0}^{\infty}{x^{2k}e^{-ax^2}\, dx}\right)\\f'(a)&=-\frac{2k+1}{2a}f(a)\\\implies f(a)&=Ca^{-(k+\frac{1}{2})}\end{align}$$
Then to find $C$, using $f(1)$ with $u=x^2$
$$\begin{align}C&=\int_{0}^{\infty}{x^{2k}e^{-x^2}\, dx}\\&=\frac{1}{2}\int_{0}^{\infty}{u^{k-\frac{1}{2}}e^{-u}\, du}\\&=\frac{1}{2}\Gamma(k+\frac{1}{2})\end{align}$$
Using $\Gamma(k+\frac{1}{2})=\frac{(2k)!}{2^{2k}k!}\sqrt{\pi}$
$$\begin{align}I&=\frac{1}{2}\sum_{k=0}^{\infty}{\frac{(-9)^k}{(2k)!}a^{-(k+\frac{1}{2})}\Gamma(k+\frac{1}{2})}\\&=\frac{\sqrt{\pi}}{2\sqrt{a}}\sum_{k=0}^{\infty}{\frac{(-9)^k}{(2k)!}\frac{(2k)!}{2^{2k}k!}a^{-k}}\\&=\frac{\sqrt{\pi}}{2\sqrt{a}}\sum_{k=0}^{\infty}{\frac{1}{k!}\left(-\frac{9}{4a}\right)^k}\\&=\frac{\sqrt{\pi}}{2\sqrt{a}}e^{-\frac{9}{4a}}\end{align}$$
