|MATLAB Function Reference|
M = magic(n)
n matrix constructed from the integers
n^2 with equal row and column sums. The order n must be a scalar greater than or equal to
A magic square, scaled by its magic sum, is doubly stochastic.
The magic square of order 3 is
magic(3) M = 8 1 6 3 5 7
This is called a magic square because the sum of the elements in each column is the same.
And the sum of the elements in each row, obtained by transposing twice, is the same.
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
There are three different algorithms:
To make this apparent, type:
rank(A); end r
If you supply
n less than
magic returns either a nonmagic square, or else the degenerate magic squares