# Expectation of function of two random variables

I have the random variables X and Y, with joint density function $f(x,y)$ over the plane $-\infty < x < \infty$ and $-\infty < y < \infty$. I am trying to find the expectation of $(X-Y)^2$.

Here is my strategy:

1) Let $Z=X-Y$

2) Find the cumulative distribution function of Z, $F_Z(z)$, by integrating over the joint density function of X and Y, using the parameters $-\infty<x<z+y$, and $-\infty<y<\infty$.

3) Differentiate $F_z(z)$ to get the probability density function of z, $f_z(z)$

4) Find the expected value of $Z^2$

I think that this method should work, but I was wondering if there is a simpler approach to solve it that doesn't use so many steps.

## 2 Answers

Integrate $(x-y)^2f(x,y)$ over the plane.

• I see, this is a much better solution. However, I was wondering, would my original method have led me to the same answer? – Luchia Dec 7 '13 at 20:56
• Yes, in principle it could have worked, sometimes. Finding the cdf of $Z$ may involve an "undoable" integral. You then differentiate it. There is a way (convolution) to bypass the integration, and get the density of $X-Y$ directly as an integral. One advantage of the expression I gave is that if integration poses difficulties, one can use numerical methods to approximate the answer. – André Nicolas Dec 7 '13 at 21:05

You could also use that $E[(X-Y)^2]=E[X^2-2XY+Y^2]=E[X^2]+2E[XY]+E[Y^2]$