I am trying to calculate the expected value of the absolute value of the difference between two independent uniform random variables.
Let $X_1\sim\operatorname{Uniform}(0, 2)$ and $X_2\sim\operatorname{Uniform}(0, 2)$ and $X_1$ and $X_2$ are independent. I want to calculate $\operatorname E \left[|X_1 - X_2|\right]$.
Can anyone please help?
For every independent random variables $X_1$ and $X_2$ with densities $f_1$ and $f_2$ and every measurable function $g$, $$ \operatorname E[g(X_1,X_2)]=\int_{D_1}\int_{D_2} g(x_1,x_2) f_1(x_1) f_2(x_2) \, \mathrm{d}x_2 \, \mathrm{d}x_1. $$ where $D_1$ and $D_2$ are the domains of $X_1$ and $X_2$. Since $f_1(x_1) = f_2(x_2) = 1/2$, and $D_1=D_2=[0,2]$ we have that
$$ \operatorname E[|X_1-X_2|]=\int_0^2\int_0^2 \frac{|x_1-x_2|}{4} \, \mathrm{d}x_2 \, \mathrm{d}x_1 =\frac{2}{3}. $$