Let $X$ and $Y$ have the following joint density:
$$f_{X,Y}(x, y) = \begin{cases} {\frac{y}{x^2}} & \text{$0 \lt y \lt x \lt 2$} \\{0} & \text{otherwise}\end{cases}$$
Give the value of $E(X−Y)$.
By linearity of expectation, $E(X-Y)=E(X)-E(Y)$. I started by obtaining the marginal distributions. I will let software do the computations as I am mainly concerned that I'm understanding the concept correctly.
$$\begin{align*} f_Y(y) &= \int_y^2\frac{y}{x^2}dx\\\\ &= \left(-\frac{y}{2}+1\right)I_{(0,2)}(y) \\\\ f_X(x) &= \int_0^x\frac{y}{x^2}dy\\\\ &= \frac{1}{2}I_{(0,2)}(x) \\\\ \end{align*}$$
Then
$$\begin{align*} E(Y) &= \int_0^2y\left(-\frac{y}{2}+1\right)dy\\\\ &= \frac{2}{3} \\\\ E(X) &= \int_0^2x\cdot\frac{1}{2}dx\\\\ &= 1 \\\\ \end{align*}$$
Finally,
$$E(X-Y)=E(X)-E(Y)=1-\frac{2}{3}=\frac{1}{3}$$
Is this a valid solution? I would also be interested in seeing alternative approaches.