There are two independent uniform continuous random variables $X$ and $Y$ (such that $0 \leq X \leq 10$, $0 \leq Y \leq 10$). The function $f$ is the difference between the two random variables ($|X-Y|$).
What is the expected value of $f(X,Y)$?
My analytic solution was $10-\sqrt{50}$. I wanted to check my answer with Monte Carlo Simulation.
I randomly chose $1M$ numbers each for $X$ and $Y$ and calculated one million $f(X,Y)$. One intuitive way of getting the expected value is averaging the million values ($\approx$ 3.33). Another way is getting the median(the distributional balance) value ($\approx$ 2.93) among the million values.
The second one was close to my analytic solution.
Maybe I am confusing different concepts. What is the right way of calculating the expected value through the MC simulation? Is my analytic answer correct? If not, how do I calculate it analytically?
updated:
After some research, it seems like the correct analytic solution should be instead(for simplication, the uniform distributions of X, Y are U(0,1) instead of U(0,10):
$E(|X-Y|) = \int_{y=0}^{1}\int_{x=0}^{1}|x-y|2(1-|x-y|)dxdy = \frac{1}{3}$
Because the p.d.f. of Z is $2(1-|x-y|)$, which is derived from the convolution function between $X$ and $-Y$.