Proof of magic square algorithm? Proof of magic square algorithm? Why does it work?    Where the algorithm to create one is to add the next number above diagonally to the right.  If you go off the grid, you wrap, as if he grid repeats.   If the spot is taken, you write the next number below the current number, and then continue building the diagonal.  I'm assuming the algorithm is known on this math forum.
 A: If the side of the square is $n$, note that the ranges $[1,n], [n+1,2n],\dots [n^2-n+1,n^2]$ each occupy a diagonal of the square, wrapping at the edges.  The starting column of each range is different, as is the starting row.  Each column of the square intersects each of these diagonals once, so the sum of the number just below the bottom of all the ranges is $0+n+2n+\dots (n-1)n=\frac 12(n-1)n^2$.  Each column intersects one of the diagonals at each point in the interval, so this adds $1+2+3+\dots n=\frac 12n(n+1)$  The total of each column is then $\frac 12((n-1)n^2+n(n+1))=\frac 12(n^3+n)$.  A similar argument works for the rows.  The main diagonal works the same way but you step throught the diagonals two steps at a time.  That works fine as long as $n$ is odd.  The other diagonal is $[n^2+1,n(n+1)]$, which sums to the same.
A: here is a different way to "generate" a 3by3 magic square: Let's call the top row positions 1,2,3. Then the middle row 4,5,6 and the bottom row 7,8,9.
Ok, here we go. Put an $x$ at pos.5 Then at pos 1 put $x+a$ and at pos 9 put $x-a$. Now at pos 3 put $x+b$ and at pos 7 put $x-b$. Then at pos 2 put $x-a-b$ and at pos 8 put $x+a+b$ Lastly at pos 4 put $x-a+b$ and at pos 6 put $x+a-b$ Now verify that all rows, columns and diagonals add up to $3x$. 
Now consider the magic square as a matrix. Then this matrix can be written as a sum of three 3by3 matrices with $x,a$ and $b$ scalars up front each matrix. Each matrix now has entries either $1,-1$ or $0$
Verify with little linear algebra that these three matrices are lin independent and form a basis for any 3by3 magic square.
By the rules of linear algebra, the sum/difference of two magic squares forms again a magic square.
