How do I calculate the expected value given this density function? I want to find the expected value of a random variable whose density function is
$$f(x) = \begin{cases}
2xe^{-x^2}, & x > 0 \\
0, &x \leq 0
\end{cases}.$$
For what's worth, all I know is the way the expected value should be found: that is, I need to put an $x$ beside $f(x)$ and then integrate it (probably, from $0$ to $\infty$). Here's where the problem turns up. I tried using Wolfram, and it shows me some weird output. In classes, we haven't covered the material concerning this, but I'm expected to be capable of doing it. But I don't know how.
 A: Guide:


*

*Consider $Y \sim N(0,\frac12)$, we can compute $Var(Y)$ and $E[Y]$. Also, we can compute $E[Y^2]$.

*Write an expression in integral form for $E[Y^2]$ and compare with what you want to compute
A: With partial integration for $h'(x)=xe^{-x^2}$ and $g(x)=2x$ you get
$$
\int_0^{\infty}xf(x)dx=\underbrace{[-xe^{-x^2}]_0^{\infty}}_{=0}-\int_0^{\infty}-e^{-x^2}=\frac{\sqrt{\pi}}{2}\text{erf}(\infty)=\frac{\sqrt{\pi}}{2}
$$
A: The density function is $f(x)= 2xe^{-x^2}$ for x> 0, 0 for $x\le 0$.  The expected value is, of course, given by $\int_{-\infty}^{\infty} xf(x)dx$ which, in this case, is 2$\int_0^\infty x^2e^{-x^2}dx$.  
To integrate that, use "integration by parts".  Let $u= x$ and $dv= x e^{-x^2}dx$.  (We need that "x" in $xe^{-x^2}$ in order to integrate.) Then $du= dx$.  To integrate $dv= x e^{-x^2}dx$ let $y= -x^2$ so that $dy= -2xdx$ and $dx= -\frac{1}{2}dy$.  $v= int xe^{-x^2}dx= -\frac{1}{2}\int e^y dy= -\frac{1}{2}e^y= -\frac{1}{2}e^{-x^2}$.
So $\int_0^{\infty} x^2 e^{-x^2}dx= \left(-\frac{1}{2}xe^{-x^2}\right)_0^{\infty}+ \frac{1}{2}\int_0^{\infty}e^{-x^2}dx= \frac{1}{2}\int_0^\infty e^{-x^2}dx$.
That last integral is pretty standard if you have dealt with the "normal distribution" but I will do it here since it is a pretty "cute" method.
let $I= \int_0^\infty e^{-x^2}dx$. It is also true that $I= \int_0^\infty e^{-y^2}dy$.  Then, $I^2= \left(\int_0^\infty e^{-x^2}dx\right)\left(\int_0^\infty e^{-y^2}dy\right)$.  By Fubini's theorem that product of integrals is the same as the double integral $\int_0^\infty\int_0^\infty e^{-x^3}e^{-y^2}dydx=$$ \int_0^\infty\int_0^\infty e^{-(x^2+ y^2)}dydx$.
Change to polar coordinates!  Then $e^{-x^2+ y^2}= e^{-r^2}$ and $dydx=  rdrd\theta$.  Since both x and y are going from 0 to $\infty$ we are integrating over the entire first quadrant.  In polar coordinates, r goes from 0 to $\infty$ and $\theta$ goes from 0 to $\frac{pi}{2}$.
So $I^2= \int_0^{\frac{\pi}{2}}\int_0^\infty e^{-r^2} rdrd\theta= \frac{\pi}{2}\int_0^\infty e^{-r^2} rdr$.
For that last integral, let $u= r^2$ so $du= 2rdr$. The integral becomes $\frac{\pi}{2}\int_0^\infty e^{-u}du= \frac{\pi}{2}\left[-e^{-u}\right]_0^\infty= \frac{\pi}{2}$.
So the expected value is $\frac{1}{2}\frac{\pi}{2}= \frac{\pi}{4}$.
