I've tried to solve the following problem. Could you please tell if I did it right.
Problem. Given a n x n square grid. We take a random rectangle so that every ractangle is equally likely.
Find expected value of area of this rectangle.
Solution. The number of all rectangles is $\sum\limits_{i=1}^{n}{i^2} = \frac{n(n+1)(2n+1)}{6}$. Let $f((i,j))$ - number of rectangles which consist of square in i-th row and j-th column. $f((i,j)) = i(n-i+1)j(n-j+1)$. Let $X_{i,j} = 1$ if random rectangle consists of square in i-th row and j-th column and $X_{i,j} = 0$ otherwise. Expected value of area of a random rectangle is $E(\sum\limits_{i=1}^{n}{\sum\limits_{j=1}^{n}{X_{i,j}}}) = \sum\limits_{i=1}^{n}{\sum\limits_{j=1}^{n}{\frac{f((i,j))}{\frac{n(n+1)(2n+1)}{6}}}}$
$= \sum\limits_{i=1}^{n}{\frac{1}{\frac{n(n+1)(2n+1)}{6}}\sum\limits_{j=1}^{n}{i(n-i+1)j(n-j+1)}} = \sum\limits_{i=1}^{n}{i(n-i+1)\frac{6}{n(n+1)(2n+1)}\sum\limits_{j=1}^{n}{j(n-j+1)}}$
$=\sum\limits_{i=1}^{n}{i(n-i+1)\frac{6}{n(n+1)(2n+1)}((n+1)\sum\limits_{j=1}^{n}{j} - \sum\limits_{j=1}^{n}{j^2})} = \sum\limits_{i=1}^{n}{i(n-i+1)\frac{6}{n(n+1)(2n+1)}(\frac{(n+1)(1+n)}{2} - \frac{n(n+1)(2n+1)}{6})}$
$=\frac{6}{n(n+1)(2n+1)}(\frac{(n+1)(1+n)}{2} - \frac{n(n+1)(2n+1)}{6})\sum\limits_{i=1}^{n}{i(n-i+1)} = \frac{6}{n(n+1)(2n+1)}(\frac{(n+1)(1+n)}{2} - \frac{n(n+1)(2n+1)}{6})^2$
The expected area is the expected base times the expected height. If, for example, $n=10$, there are $10$ bases of length $1$, and $9$ of length $2$, on up to $1$ of length $n$: $\sum_{k=1}^n k$ in all. Thus the expected base length is $$b = \frac{\sum_{k=1}^n k ( n+1-k)}{\sum_{k=1}^n k}$$ and the expected height length is the same. So the expected area is $b^2$.