# variance of a function of random variables

#### james92

##### New Member
Hi all,

I'm trying to calculate the variance of a function of two continuous random variables and could do with a nudge in the right direction seeing as its been a good few years since I did any probability theory work. You may also notice that my latex is a little ropey too...

Specifically I need to calculate var(z):

$z = x-y, x>y$
$z= 0, x<y$

where x and y are both iid uniform(a,b)

If it helps:
$E(z|x)=\frac{(x-a)^2}{2(b-a)}$
$E(z)=\frac{b-a}{6}$
$var(z|x)=\frac{(x-a)^3}{3(b-a)}-\frac{(x-a)^4}{4(b-a)^2}$

Is the law of total variance relevant? Any help greatly appreciated

#### BGM

##### TS Contributor
Without investigating any good tricks to solve this problem, you can always refer back to the fundamental definition:

$Var[Z] = E[Z^2] - E[Z]^2$

$= \int_a^b \int_y^b \frac {(x - y)^2} {(b - a)^2} dxdy - E[Z]^2$

provided that you already calculated $E[Z]$