M = magic(n)
M = magic(n), for
n>= 3, is an
nmatrix constructed from the integers 1 through
n^2with equal row and column sums. A magic square, scaled by its magic sum, is doubly stochastic.
This is called a magic square because the sum of the elements in each column is the same.
M = magic(3)
8 1 6
3 5 7
4 9 2
And the sum of the elements in each row, which can be obtained by transposing twice, is the same.
15 15 15
This is also a special magic square because the diagonal elements have the same sum.
The value of the characteristic sum for a magic square of order
n = 3, is
n, one for even
nnot divisible by four, and one for even
ndivisible by four.
The following demonstration makes this apparent:
for n = 3:20
A = magic(n);
r(n) = rank(A);
(c) Copyright 1994 by The MathWorks, Inc.