closed-form solution for summed squared error of $n\times n$-grid points to center of gravity

33 Views Asked by At

The context of my problem is the construction of test problems for the $k$-means algorithm and variants of it. The problems should have known optima and are thus constructed from a basic building block which is a regular $n\times n$ grid of data points filling the unit square. For $n=2$ the point set would be {(0,0),(0,1),(1,0),(1,1)} for $n=3$ the point set would be {(0,0),(0,0.5),(0,1),(0.5,0),(0.5,0.5),(0.5,1),(1,0),(1,0.5),(1,1)} and so on.

I like to know the sum of squared distances of all grid points for a given $n$ to the center of gravity which is the point (0.5,0.5).

The naive formula is the following:

$$\mbox{SSE}(n) = \sum_{i=0}^{n-1}\sum_{j=0}^{n-1} (0.5-\frac{i}{n-1})^2+(0.5-\frac{j}{n-1})^2$$ E.g. $$\mbox{SSE}(2)=2$$

Does a closed-form solution for $\mbox{SSE}(n)$ exist (and how does it look)?

Addendum: Following the remark of @Ian I think one can rewrite the sum as $$\mbox{SSE}(n)=2n \sum_{i=0}^{n-1} (0.5-\frac{i}{n-1})^2$$

which is basically a sum of powers of 2 as described in Sum of powers of natural numbers. I should be able to figure out the final formula from here.

Addendum 2: And here is the formula: $$\mbox{SSE}(n)=\frac{n^3+n^2}{6(n-1)}$$