# Relation to all-pairs Euclidean distances

Given $d$-dimensional coordinates residing in a matrix $X\in\mathbb{R}^{n\times d}$, the Euclidean distance between items $i$ and $j$ is denoted as $g_{ij}$. Let $c\in\mathbb{R}^d$ denote the centroid of the configuration $X$. Is it possible to establish a relation between $$\sum_{i,\, j} g_{ij}^2,$$ and $$\sum_{i=1}^n g_{ic}^2,$$where $g^2$ is a squared Euclidean distance? My solution shows that the first is $2n$ times the second. Is this correct?

Yes. Assume wlog that the centroid is at zero. Then $\sum_i x_i=0$, whence $\sum_{i,j} g_{ij}^2 = \sum_{i,j}\|x_i-x_j\|^2=\sum_{i,j}\|x_i\|^2-2\sum_{i,j}x_i^Tx_j+\sum_{i,j}\|x_j\|^2$. This simplified to $n\sum_i|x_i\|^2-0+n\sum_j\|x_i\|^2=2n\sum_{i}\|x_i\|^2$.