# Simplifying the sum $\sum_{i=1}^n \sum_{j=i+1}^n({(x_i-x_j)}^2+{(y_i-y_j)}^2)$

I am trying to evaluate the sum here , $$\sum_{i=1}^n \sum_{j=i+1}^n({(x_i-x_j)}^2+{(y_i-y_j)}^2)$$

How do this sum can be simplified to $$n\sum_{i=1}^n({x_i}^2+{y_i}^2) - {(\sum_{i=1}^n{x_i})}^2-{(\sum_{i=1}^n{y_i})}^2$$ .

I need to understand the intermediate steps here.Thanks in advance

Note that due to symmetry $$\sum\limits_{i = 1}^n {\sum\limits_{j = i + 1}^n {{{\left( {{x_i} - {x_j}} \right)}^2}} } = \frac{1}{2}\sum\limits_{i = 1}^n {\sum\limits_{j = 1}^n {{{\left( {{x_i} - {x_j}} \right)}^2}} }$$, so that by expansion of the square and then sum, we have $$\sum\limits_{i = 1}^n {\sum\limits_{j = i + 1}^n {{{\left( {{x_i} - {x_j}} \right)}^2}} } = \frac{1}{2}\sum\limits_{i = 1}^n {\sum\limits_{j = 1}^n {{x_i}^2} } + \frac{1}{2}\sum\limits_{i = 1}^n {\sum\limits_{j = 1}^n {{x_j}^2} } - \sum\limits_{i = 1}^n {\sum\limits_{j = 1}^n {{x_i}{x_j}} }$$Now, the first and second terms in the R.H.S. of the above equation are the same and the third one is $\sum\limits_{i = 1}^n {{x_i}} \sum\limits_{j = 1}^n {{x_j}}$. I hope you could see your answer by now.
• I understood the first and second term , but could you elaborate the last term $\sum_{i=1}^nx_i\sum_{j=1}^nx_j$ a bit more. Commented Aug 23, 2014 at 6:42