Magic函数

magic函数

MATLAB其实有一个组建函数,其能够创建任意尺寸的魔方,没有什么奇怪的,这个函数的名称是magic。

B = magic(4)
B =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

这个矩阵与Dürer 版画相同和所有相同的"magic"特性;仅仅不同的是两个被互换的中间列。

交换两个中间列使这个B变为Dürer的A。

A = B(:,[1 3 2 4])

这说明,矩阵B的每列,在命令1,3,2,4中改变元素。它产生

A =
    16     3     2    13
     5    10    11     8
     9     6     7    12
     4    15    14     1

当他能够使用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.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值