Professional Documents
Culture Documents
http://ebooks.cambridge.org/
Chapter
8 - Magic Squares pp. 101-107
Chapter DOI: http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge University Press
8
Magic Squares
102
Magic Squares
8.1 Introduction
This project is about magic squares. An n x n magic square is an n x n
matrix of real numbers with the following property:
All rows, all columns and the two 'main' diagonals of the matrix add up to the
same number, r say, called the magic constant.
For example,
has this property for r = 6. The two main diagonals in this case are
3 + 2 + 1 (top left to bottom right) and 2 + 2 + 2 (top right to bottom
left).
There are many algorithms for producing magic squares with the additional property that the entries are the integers 1,2,... , n 2 in some
order. For example, with n = 3,
(8.1)
The MATLAB function magic does this (try typing magic(3)). In this
project we shall not go into these algorithms but instead investigate the
algebra underlying magic squares, using your knowledge of matrices and
solution of linear equations.
012 ai3
a 2 2 CL23
Thus there are nine entries a n , . . . , 033. Explain why, writing down the
conditions for all rows, all columns and the two main diagonals to add
to the same number r, we get the condition M v = 0, where M is the
Cambridge
Books Online Cambridge University Press, 2010
Downloaded from Cambridge Books Online by IP 81.180.218.225 on Fri Apr 22 09:40:20 BST 2016.
http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge Books Online Cambridge University Press, 2016
8 . 2 Magic
squares
size
3 x 3
103
8 x 10 matrix
/ - 1 1 1
- 1 0 0
- 1 0 0
- 1 1 0
- -11 0 1
-1 0 0
-1 1 0
1
0
0
0
0
1
0
0
1
0
1
0
0
0
0
1
0
0
1
0
1
0 0 0 0 \
1 0 0 0
0
1 1 1
0 1 0 0
0 0 1 0
1 0 0 1
0 0 0 1
- 1 0 0 1 0 1 0 1 0 0 /
an
ai 2
13
a 22
are all magic squares. Why does it follow from (ii) that every 3x3 magic
square A can be written uniquely in the form of a linear combination
A=
H~
Cambridge
Books Online Cambridge University Press, 2010
Downloaded from Cambridge Books Online by IP 81.180.218.225 on Fri Apr 22 09:40:21 BST 2016.
http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge Books Online Cambridge University Press, 2016
104
Magic Squares
for Ai, A2, A3 G R? (Hint: You are being asked to show that E\, E2, E3
form a basis for the three-dimensional subspace of magic squares. Since
there are three matrices E{ it is enough to show that they are linearly
independent, considered as vectors in R 9 .) What are the A^ when A is
given by (8.1) above?
(iv) A 3 x 3 matrix has, in addition to its two 'main' diagonals, four
other 'broken' diagonals:
Gil + 23 + 32, Gi2 + a 21 + 33, &13 + O>21 + ^32, &12 + &23 + &31-
If, for a magic square A, we require in addition all the broken diagonals to add up to the same magic constant r, then the square is called
pandiagonal.
In general, a n n x n matrix has two main diagonals and 2n 2 broken
diagonals, and if all these and all the rows and all the columns add up
to the same r, then the matrix is a pandiagonal magic square.
In the 3 x 3 case, expand your matrix M by the addition of four rows
corresponding to the four broken diagonals and use the new matrix (Ml
say) to show that the only pandiagonal magic squares are XE3 for A G R.
(Thus you should find from the row reduced echelon form of M l that
only one entry of A is now arbitrary, and the others are all equal to this
one.)
(v) We now look at products of 3 x 3 magic squares. By (iii) the product
of two such squares has the form
(X1E1 + X2E2 + X3E3)(fi1E1
+ /i 2 2 + /X3S3).
(8.2)
Let
Cambridge
Books Online Cambridge University Press, 2010
Downloaded from Cambridge Books Online by IP 81.180.218.225 on Fri Apr 22 09:40:21 BST 2016.
http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge Books Online Cambridge University Press, 2016
105
4 x 4
Cambridge
Books Online Cambridge University Press, 2010
Downloaded from Cambridge Books Online by IP 81.180.218.225 on Fri Apr 22 09:40:21 BST 2016.
http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge Books Online Cambridge University Press, 2016
106
Magic Squares
for a=l:4
for b=l:4
if b~=a
for c=l:4
if c~=a & c~=b
for d=l:4
if d~=a k d~=b & d~=c
p= [a b c d] ;
end;
end;
end;
end;
end;
end;
end;
After the permutation p is found, you will want to calculate the permutation matrix, then test whether it is magic. The quickest way to do this
is to use the criterion M v = 0 as in Question (i) in 8.2. Now, however,
M will be the 10 x 17 matrix you have just found, and v will be a 17 x 1
column vector of the form (1 a n . . . a^)T.
(iii) Add more rows to your matrix M to test for pandiagonal 4 x 4 magic
squares (see Question (iv) in 8.2 for the definition). Call the resulting
matrix M l . What is the dimension of the space now? Are any of these
given by permutation matrices?
(iv) By finding the reduced row echelon form of your matrix M l , show
that every 4 x 4 pandiagonal magic square has the form
a b c + d-\-e
b+c-d+e
-a + 2c + 2d
2b
a + b + c-\-d + e a+bcd+e
a + 6 + 3c + <i e
b+c+d-e
a-2c + 2e
b-c+d+e
a
2c
-6+c+d+e
-a + 2b + 2c
2d
2e
Cambridge
Books Online Cambridge University Press, 2010
Downloaded from Cambridge Books Online by IP 81.180.218.225 on Fri Apr 22 09:40:21 BST 2016.
http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge Books Online Cambridge University Press, 2016
(optional)
107
matrix, that is, the sum of the entries in the leading diagonaltop left
to bottom right.)
(optional)
Find out what you can about the dimension of the space of 5 x 5 magic
squares, and of the pandiagonal ones. Are the pandiagonal ones spanned
in this case by permutation matrices? If so, find a basis consisting of
permutation matrices. (You can find details in the article [16].)
Cambridge
Books Online Cambridge University Press, 2010
Downloaded from Cambridge Books Online by IP 81.180.218.225 on Fri Apr 22 09:40:21 BST 2016.
http://dx.doi.org/10.1017/CBO9780511624117.009
Cambridge Books Online Cambridge University Press, 2016