A problem about the convergence of an improper integral Let $f:\mathbb R\longrightarrow\mathbb R$ be a function with 
$$f(x)=\frac{1}{3}\int_x^{x+3} e^{-t^2}dt$$
and consider  $g(x)=x^nf(x)$ where $n\in\mathbb Z$. 

I have to discuss the convergence of the integral 
  $$\int_{-\infty}^{+\infty}g(x)dx$$ at the varying of $n\in\mathbb Z$.

Any idea? We have an integral of an "integral function", and I'm a bit confused!
Thanks in advance.
 A: Hint: $$0 \leq f(x) \leq \frac13\cdot 3e^{-\min(x^2, (x+3)^2)} \leq e^{-x^2}+e^{-(x+3)^2}$$
A: Hint: try weighing your function using a test function that will make your function converge and use a Lebesgue or Riemann-Stijltes integral...
A: Clearly, $f\in \mathcal C^1(\mathbb R, \mathbb R)$.
If $x>0$, then for $t\in [x,x+3]$ we have $e^{-t^2}\le e^{-x^2}$. In the same spirit,
if $x<-6$, then for $t\in [x,x+3]$ we have $e^{-t^2}\le e^{-(x+3)^2}$. Thus, we obtain
$$f(x)\le e^{-x^2},\quad x>0,$$
$$f(x)\le e^{-(x+3)^2},\quad x<-6.$$
We will say that $$\bar f(x)=\begin{cases}e^{-x^2},&x>0,\\
f(x),&x\in[-6,0],\\e^{-(x+3)^2},&x<-6.\end{cases}$$
It's evident that $0<f\le \bar f$.
Another useful property of $f$ is that it's never zero, and $f(0)\ge e^{-9}$. As a consequence, for $n\le -1$ $g(n, x)$ is not integrable, because in the neighbourhood of zero $g(n,x)\sim \mathcal O(x^n)$; now we are left with non-negative $n$.
We study $\int_\mathbb R |g(n,x)|dx$. By comparison criterion, it's sufficient to prove that the following integral exists:
$$\int_\mathbb R |x|^n \bar f(x)dx.$$
We split it:
$$\int_\mathbb R |x|^n \bar f(x)dx=\int_{-\infty}^{-6}|x|^ne^{-(x+3)^2}dx + \int_{0}^{ \infty}|x|^ne^{- x  ^2}dx+\int_{-6}^{0}|x|^nf(x)dx.$$
First and second terms in this sum exist because the exponent there decreases on infinity faster than any polynomial (gaussian random variables have all moments, as another approach). The last term exists, because it's an integration over a compact of a continuous function. Therefore, for $n\ge 0$ $\int_\mathbb R |x|^n \bar f(x)dx<\infty$, it yields that for $n\ge 0$ $\int_\mathbb R |x|^n  f(x)dx<\infty$, or in other words, for $n\ge 0$ the function $g(n,x)$ is integrable.
A: I think I can give you expression for $\int_{-\infty}^{\infty}g(x)\ dx$. Then, we can think about how it should converge.
We start by noting that $$\large f(x)=\frac{\sqrt{\pi}}{3}\left(Q\left(\sqrt{2}x\right)-Q\left(\sqrt{2}(x+3)\right)\right)$$ and $$\large f(-x)=\frac{\sqrt{\pi}}{3}\left(-Q\left(\sqrt{2}x\right)+Q\left(\sqrt{2}(x-3)\right)\right)$$
Also we keep in mind that  $$\large I=\int_{-\infty}^{\infty}g(x)\ dx=\int_{-\infty}^{\infty}x^nf(x)\ dx\\ \large =\int_{0}^{\infty}\left(x^nf(x)+(-x)^nf(-x)\right)\ dx $$
Case $1$: $n$ even 
In this case, 
\begin{equation}
\large
\begin{split}
I=&\int_{0}^{\infty}x^n\left(f(x)+f(-x)\right)\ dx\\
\ =& \frac{\sqrt{\pi}}{3}\int_{0}^{\infty}x^n\left(Q\left(\sqrt{2}(x-3)\right)-Q\left(\sqrt{2}(x+3)\right)\right)\ dx\\
\ =& \frac{\sqrt{\pi}}{3}\int_{0}^{\infty}\frac{x^n}{\sqrt{2\pi}}\int_{\sqrt{2}(x-3)}^{\sqrt{2}(x+3)}\exp\left({-\frac{u^2}{2}}\right)\ du \ dx\\
\ =&\frac{1}{3}\int_{0}^{\infty}x^n\int_{x-3}^{x+3}\exp\left({-\frac{u^2}{2}}\right)\ du \ dx\\
\end{split}
\end{equation}
Now, if the order of integration is changed then, as one can verify without much difficulty, we get the following two integrals $$\large I=I_1+I_2$$ where $$\large I_1=\frac{1}{3}\int_{-3}^{3}e^{-u^2}\int_{0}^{u+3}x^n\ dx\ du\\
\large =\frac{1}{3(n+1)}\int_{-3}^{3}e^{-u^2}(u+3)^{n+1}\ du\\ \large =\frac{1}{3(n+1)}\int_{0}^{3}e^{-u^2}\left\{(u+3)^{n+1}-(u-3)^{n+1}\right\} \ du\\ \large (\mbox{Since}\  n \ \mbox{is even})\\
\large I_2=\frac{1}{3}\int_{3}^{\infty}e^{-u^2}\int_{u-3}^{u+3}x^n\ dx\ du\\
\large =\frac{1}{3(n+1)}\int_{3}^{\infty}e^{-u^2}\left\{(u+3)^{n+1}-(u-3)^{n+1}\right\} \ du$$
Then,
\begin{equation}
\large
\begin{split}
I=& I_1+I_2\\
\ =& \frac{1}{3(n+1)}\int_{0}^{\infty}e^{-u^2}\left\{(u+3)^{n+1}-(u-3)^{n+1}\right\} \ du\\
\ =& \frac{1}{3(n+1)}\int_{-\infty}^{\infty}e^{-u^2}(u+3)^{n+1} \ du\ (\mbox{Since}\ n \ \mbox{is even})\\
\ =& \frac{1}{3(n+1)}\int_{-\infty}^{\infty}e^{-(u-3)^2}u^{n+1} \ du\\
\ =& \frac{\sqrt{\pi}}{3(n+1)}\mathbb{E}(X^{n+1})
\end{split}
\end{equation} where $\displaystyle X\sim \mathcal{N}\left(3,\frac{1}{2}\right)$. 
Case $2$: $n$ odd
In this case, 
\begin{equation}
\large
\begin{split}
I=& \int_{0}^{\infty}x^n(f(x)-f(-x))\ dx\\
\ =& \frac{\sqrt{\pi}}{3}\int_{0}^{\infty}x^n
\left[2Q\left(\sqrt{2}x\right)-Q\left(\sqrt{2}(x+3)\right)-Q\left(\sqrt{2}(x-3)\right)\right]\ dx\\
\ =& \frac{2I_2-(I_1+I_3)}{3}\\
\end{split}
\end{equation}
Now, \begin{equation}
\large
\begin{split}
I_1=&\sqrt{\pi}\int_{0}^{\infty}x^nQ\left(\sqrt{2}(x+3)\right)\ dx\\
\ =&\int_{0}^{\infty}x^n \int_{x+3}^{\infty}\exp\left(-u^2\right)\ du \ dx\\
\ =&\int_{3}^{\infty}\exp\left(-u^2\right) \int_{0}^{u-3}x^n\ dx \ du\ (\small \mbox{Interchanging order of integration})\\
\ =&\frac{1}{n+1}\int_{3}^{\infty}\exp\left(-u^2\right)(u-3)^{n+1} \ du\\
\ =&\frac{1}{n+1}\int_{3}^{\infty}\exp\left(-(u+3)^2\right)u^{n+1} \ du\\
\ =&\frac{1}{n+1}\int_{-\infty}^{0}\exp\left(-(u-3)^2\right)u^{n+1} \ du\ (\because\ n\ \mbox{is odd})\\
\end{split}
\end{equation}
Similarly, we will get $$\large I_3=\frac{1}{n+1}\int_{0}^{\infty}\exp\left(-(u-3)^2\right)u^{n+1} \ du$$
and \begin{equation}
\begin{split}
I_2=&\int_{0}^{\infty}\exp\left(-u^2\right) \int_{0}^{u}x^n\ dx \ du\\
\ =&\frac{1}{n+1}\int_{0}^{\infty}\exp\left(-u^2\right) u^{n+1} \ du\\
\ =&\frac{1}{2(n+1)}\Gamma\left(1+\frac{n}{2}\right)
\end{split}
\end{equation}
So, $$\large I=\frac{\Gamma\left(1+\frac{n}{2}\right)-\int_{-\infty}^{\infty}\exp\left(-(u-3)^2\right)u^{n+1} \ du}{3(n+1)}\\
\large =\frac{\sqrt{\pi}}{3(n+1)}\left(\frac{(2n-1)!!}{2^n}-\mathbb{E}\left(X^{n+1}\right)\right)\\
\large =\frac{\sqrt{\pi}}{3(n+1)}\left(\mathbb{E}(Y^{2n})-\mathbb{E}\left(X^{n+1}\right)\right)$$ where $\displaystyle X\sim \mathcal{N}\left(3,\frac{1}{2}\right),\ Y\sim \mathcal{N}\left(0,\frac{1}{2}\right)$.
A: Basically, you are considering the integral
$$ I := \frac{1}{3}\int_{-\infty}^{\infty}x^n f(x) dx= \frac{1}{3}\int_{-\infty}^{\infty}x^n \int_{x}^{x+3}e^{-t^2}dt \,dx.$$ 
Changing the order of integration yields
$$ I = \frac{1}{3}\int_{-\infty}^{\infty}e^{-t^2} \int_{t-3}^{t}x^ndx \,dt $$
$$ = \frac{1}{3}\int_{-\infty}^{\infty}e^{-t^2}\left(\frac{t^{n+1}-(t-3)^{n+1}}{n+1} \right) \,dt $$
$$ = \frac{1}{3(n+1)}\int_{-\infty}^{\infty}t^{n+1} e^{-t^2} dt - \frac{1}{3(n+1)}\int_{-\infty}^{\infty}(t-3)^{n+1} e^{-t^2} dt dt $$

$$\implies I = \frac{1}{3(n+1)} I_1 + \frac{1}{3(n+1)} I_2. $$

Now, note this, for $n\in \mathbb{N} \cup \left\{ 0\right\}$, $I_1$ is convergent (see the analysis for the case $I_2$ at the end of the answer) and can be evaluated in terms of the gamma function as

$$ I_1 = \frac{1}{2}\, \left( 1+ \left( -1 \right)^{n+1} \right) \Gamma  \left( \frac{n}{2}
+1 \right).$$

Examining the convergence of $I_2$ $n\in \mathbb{N} \cup \left\{ 0\right\}$, we have
$$ I_2 = \int_{-\infty}^{\infty}(t-3)^{n+1} e^{-t^2} dt = \int_{-\infty}^{\infty}y^{n+1} e^{-(y+3)^2} dy $$
$$ = (-1)^n \int_{0}^{\infty}y^{n+1} e^{-(y-3)^2} dy + \int_{0}^{\infty}y^{n+1} e^{-(y+3)^2} dy $$
$$ I_2 = I_{21} + I_{22}. $$
Now, both of the integrals $I_{21}$ and $I_{22}$ converge, since

$$ y^{n+1}e^{-(y-3)^2} \leq e^{y} e^{-(y-3)^2}, \quad y^{n+1}e^{-(y+3)^2}\leq e^{y} e^{-(y+3)^2} $$ 

and 

$$ \int_{0}^{\infty} e^{y} e^{-(y-3)^2}dy <\infty,\quad  \int_{0}^{\infty} e^{y} e^{-(y+3)^2}dy <\infty. $$

You can check Gaussian Integrals for the last two inequalities.
Note: For the case $n$ is negative integer, we have

1) If $n=-1$, then $I_1$ and $I_2$ converge.
2) If $n$ is a negative even integer, then $I_1$ and $I_2$ are undefined.
3) If $n$ is a negative odd integer, then $I_1$ and $I_2$ diverges to infinity. 

A: I interpret the question as follows: is the function $g$ integrable (in the Lebesgue sense) on $\mathbb R$? And my answer is essentially the same as TZakrevskiy's.
The function $f$ is continuous on $\mathbb R$, so $g$ is continuous on $\mathbb R\setminus\{ 0\}$ (and continuous on $\mathbb R$ is $n\geq 0$). We have to check when $g$ is integrable at $\pm\infty$ and integrable around $0$.
By the definition of $f$, we have $\vert f(x)\vert\leq e^{-x^2}$
for $x>0$ and $\vert f(x)\vert\leq e^{-(x+3)^2}$ for $x\leq -3$. It follows that 
$x^{n+2}f(x)\to 0$ as $\vert x\vert\to \infty$, so $g(x)=x^nf(x)=0(\frac1{x^2})$ as $\vert x\vert\to\infty$ and there is no integrability problem for $g$ at $\pm\infty$, for any $n\in\mathbb Z$. 
So the question is whether $g$ is integrable around $0$ or not. 
Now, $f$ is continuous with $f(0)=\int_0^3 e^{-t^2}dt\neq 0$. So $f(x)\sim f(0)$ as $x\to 0$ and $g(x)\sim f(0) x^n$. Hence, $g$ is integrable around $0$ if $n\geq 0$ and not integrable around $0$ if $n<0$.
In summary: $g$ is integrable on $\mathbb R$ if and only if $n\geq 0$.
