How to solve this problem :
Let $Y ∼ exp (3)$. The random variable X is defined as follows: first we observe the value of Y, and if $Y = y$ then we pick X uniformly in the interval $[y, 3y]$.
Compute the covariance of X and Y?
My current thought process is: $Cov(X,Y)=E[XY]-E[X]\cdot E[Y]$
I know that $E[Y]=\frac{1}{3}$ and $E[XY]\ne E[X]\cdot E[Y]$ but how to find $E[XY]$ and $E[X]$ ?
The conditional distribution of $X$ given $Y$ is uniform on $[Y, 3Y]$, so $\mathbb{E}[X\vert Y] = 2Y$. Then $$\mathbb{E}[X] =\mathbb{E}[\mathbb{E}[X\vert Y]] = 2\mathbb{E}[Y] $$ and $$\mathbb{E}[XY] = \mathbb{E}[\mathbb{E}[X\vert Y]Y] = 2\mathbb{E}[Y^2].$$ Finally $$\text{Cov}(X, Y) = 2\mathbb{E}[Y^2] - 2\mathbb{E}[Y]^2 = 2\text{Var}(Y) = \frac{2}{9}. $$