magic函数 |
MATLAB其实有一个组建函数,其能够创建任意尺寸的魔方,没有什么奇怪的,这个函数的名称是magic。 B = magic(4) 这个矩阵与Dürer 版画相同和所有相同的"magic"特性;仅仅不同的是两个被互换的中间列。 交换两个中间列使这个B变为Dürer的A。 A = B(:,[1 3 2 4]) 这说明,矩阵B的每列,在命令1,3,2,4中改变元素。它产生 A = 当他能够使用MATLAB命令的时候,为什么Dürer要进行改编列的麻烦?无疑他想要包含版画的数据,1514,在它的魔方的底层。 |
The magic Function
MATLAB actually has a built-in function that creates magic squares of almost any size. Not surprisingly, this function is named magic.
B = magic(4)
B =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
This matrix is almost the same as the one in the Dürer engraving and has all the same "magic" properties; the only difference is that the two middle columns are exchanged.
To make this B into Dürer's A, swap the two middle columns.
A = B(:,[1 3 2 4])
This says, for each of the rows of matrix B, reorder the elements in the order 1, 3, 2, 4. It produces
A =
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
Why would Dürer go to the trouble of rearranging the columns when he could have used MATLAB ordering? No doubt he wanted to include the date of the engraving, 1514, at the bottom of his magic square.