r = zeros(1,33); for n = 3:33 r(n) = rank(magic(n)); end bar(r) xlabel('n') ylabel('rank') title('rank(magic(n))') snapnowWe can clearly see three different cases. Odd order magic squares have full rank, singly even order magic squares have rank equal to roughly half their order, and doubly even order magic squares of any order have rank equal to three. Why is that? It reflects the three different cases in the MATLAB magic square generator.
[I,J] = ndgrid(1:n); A = mod(I+J+(n-3)/2,n); B = mod(I+2*J-2,n); M = n*A + B + 1;It is not hard to prove that A and B have full rank and so it is likely that their sum has full rank as well. There are many other magic squares besides the ones generated by MATLAB. Are all the odd ordered ones nonsingular? Frankly, I have no idea. The magic square property tells us very little about linear independence. Does anybody know of a 5-by-5 magic square that is also a singular matrix? I would love to see it. Or, can anybody prove that odd-ordered magic squares must be nonsingular? I would love to see a proof as well. Actually, I better see just one or the other.
1* 2 3 4* 5 6* 7* 8 9 10* 11* 12 13* 14 15 16*Now regard the marked elements as a one-dimensional array and flip that array end-for-end. This produces magic(4).
16* 2 3 13* 5 11* 10* 8 9 7* 6* 12 4* 14 15 1*It must be easy to describe that indexing operation in matrix terms in a way that generalizes to higher order and explains why the resulting matrix happens to have rank 3. But I don't see how today. Did Dürer Intentionally Show Only His Second-Best Magic Square? (I won't spoil Bill's punch line by revealing the answer to the question he poises in his title.) In order to investigate Dürer's possible choices for a special magic square, Press describes a seven variable parameterization of the 16 elements in a 4-by-4 array that characterizes all possible magic squares of order 4. (He attributes the parameterization to Maurice Kraitchik.) This approach leads to a program, enumerate.m, that checks the rank of all magic squares of order 4. This is the first time I have ever written a MATLAB code with for loops nested seven deep. It generates
= 57657600matrices. Of these, only 7040 pass the check in the inner block to qualify as legal magic squares. Dividing the final counts by 8 to account for eight-fold symmetry, we find that that there are 880 magic squares of order four. Their ranks are
rank count 3 640 4 240So, there ware nonsingular 4-by-4 magic squares. Other than that, I attach no great significant to the actual counts. The process of finding them is more interesting than the counts themselves. By the way, the entire computation by enumerate4 takes about 415 seconds on my Lenovo X201 2.67 GHz i7 laptop. The first nonsingular 4-by-4 magic square that enumerate4 finds is
1 2 16 15 13 14 4 3 12 7 9 6 8 11 5 10
p = n/2; A = magic(p); M = [A A+2*p^2; A+3*p^2 A+p^2];This M has equal column sums, but not equal row sums. And, since A has rank $n/2$, this M has rank $n/2+1$ The next step interchanges some blocks of elements to correct the row sums.
i = (1:p)'; k = (n-2)/4; j = [1:k (n-k+2):n]; M([i; i+p],j) = M([i+p; i],j);It turns out that this step does not change the rank. Now this M has equal row and column sums, but its diagonal sums are not quite right. The final step swaps two pairs of elements to correct the diagonal.
i = k+1; j = [1 i]; M([i; i+p],j) = M([i+p; i],j);This is a rank one change that produces the final magic square and increases the rank to $n/2+2$. Did Dürer Intentionally Show Only His Second-Best Magic Square?, 2009. CBM, Magic Squares chapter of Experiments with MATLAB, 2011.
Get the MATLAB code Published with MATLAB® R2012b
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.