三个矩阵的乘积最终会得到一个奇数块矩阵?
在下面的mathematica代码中,
a1 = {{0, -I}, {I, 0}}
a2 = {{0, 1}, {1, 0}}
a3 = {{1, 0}, {0, -1}}
c = I*a1*a2 // MatrixForm
d = c*a3 // MatrixForm
d的显示显示为一个二乘二的矩阵,其中1,1和2,2元素本身就是2x2矩阵,而我希望它是一个普通的旧2x2标量矩阵?
In the following bit of mathematica code
a1 = {{0, -I}, {I, 0}}
a2 = {{0, 1}, {1, 0}}
a3 = {{1, 0}, {0, -1}}
c = I*a1*a2 // MatrixForm
d = c*a3 // MatrixForm
The display of d shows up as a two by two matrix, where the 1,1 and 2,2 elements are themselves 2x2 matrixes, whereas I expect it to be a plain old 2x2 matrix of scalars?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我得到的 d 的输出:
This is the output I get for d:
这是 Mathematica 中的经典陷阱之一。
MatrixForm
显示包装器的优先级高于Set
运算符 (=
)。假设(根据您的标签选择)您打算使用矩阵乘法
Dot
(.
) 而不是 Times (*
),我会写分别返回
c
和d
:编辑:
我忘记提及如果您确实输入
然后快速查看
c
的FullForm
将告诉您问题是什么:您可以看到它有
Head [c] == MatrixForm
因此它不能与其他矩阵很好地配合。This is one of the classic gotchas in Mathematica.
The
MatrixForm
display wrapper has a higher precedence than theSet
operator (=
).Assuming (based on your tag selection) that you meant to use matrix multiplication
Dot
(.
) instead of Times (*
), I would writewhich returns for
c
andd
respectively:Edit:
I forgot to mention if you do enter
Then a quick look at the
FullForm
ofc
will show you what the problem is:You can see that it has the
Head[c] == MatrixForm
and so it won't play nice with the other matrices.