Building Odd-ordered Magic Squares

In this article we will introduce a way to build magic squares of odd order.

A simple building block

Consider the following n-by-n matrix.

This matrix is created by filling a diagonal with 0, the diagonals next to it with ±1, and then ±2, until all n diagonals are filled. Here, each diagonal “wraps” around the border of the matrix and contains exactly n entries (henceforth also called cells).

The sum of each row is 0, because it contains {-(n-1)/2, ..., -1, 0, 1, ..., (n-1)/2} exactly once. Similarly, the sum of each column is 0.

The sum of each diagonal is also 0, due to the symmetry of the matrix as an odd function.

Now we rotate this matrix by 90°, and multiply it by n:

Similarly, every row, column, and diagonal of this matrix has a sum of 0.

We add the two matrices cell-by-cell, and then add each cell by the same number (n² + 1) / 2:

Clearly, each row, column, and diagonal of this matrix sums up to the same number — because the two constituent matrices both satisfy this condition. Since it uses each whole number from 1 to exactly once, it is a magic square of order n.

Odd and even

It is not obvious why this matrix should contain all integers from 1 to exactly once, without duplicate or missing numbers. We'll take a closer look.

In the above matrix, we start at the red cell in the top row and go down along two diagonals.

All cells on the orange diagonal (going lower-left) used the same component in the first constituent matrix, whereas all cells on the blue diagonal (going lower-right) did so in the second constituent. Notice how the distance between colored cells grows by 2 every time a we go down a row.

Because n is odd, the two diagonals will “pass each other by” when they meet, instead of intersecting. As a result, no other cell in the matrix shares the same two constituents as the red cell.

Due to symmetry, this works for all other cells.

Since every integer from 1 to can be written uniquely as

(n² + 1) / 2 + ni + j, where i, j are in {-(n-1)/2, ..., -1, 0, 1, ..., (n-1)/2},

we know that no two cells may contain the same constituents, and therefore must hold two different numbers.

Beyond simple diagonals

We can generalize this method to create more magic squares. First, let's consider the following coordinate system for the square grid:

For a pair of coefficients a = a, b = b, we can write a linear function

V1 = ai + bj = ai + bj

and plot it on the grid. Here we do all calculations modulo n, but ensure the remainder is as close to 0 as possible (that is, one of {-(n-1)/2, ..., -1, 0, 1, ..., (n-1)/2}).

Due to symmetry, we know that each diagonal sums up to 0. When both a and b are coprime to n, each row and each column also contains each remainder exactly once, so that this square may be used as a constituent matrix of the desired magic square.

We choose another linear function:

V2 = ci + dj = ci + dj

then multiply it by n (no modulo this time) to obtain a second constituent matrix:

Adding the two constituent matrices together, then adding (n² + 1) / 2 so that the smallest number becomes 1, we get:

If (ad - bc) is coprime with n, this matrix will contain all numbers from 1 to exactly once, and is therefore a magic square.

Extreme use of symmetry

This method can be extended by choosing an odd bijective function from {-(n-1)/2, ..., -1, 0, 1, ..., (n-1)/2} to {-(n-1)/2, ..., -1, 0, 1, ..., (n-1)/2} and applying it on each constituent matrix. This will give rise to a whole family of magic squares, which we will also enumerate. I should pause this article here due to busyness — but I plan to come back and complete it on a future date!