如何在 Mathematica 中以编程方式显示分区矩阵?
我知道使用“插入”菜单,您可以创建一个具有垂直线和水平线的矩阵,但不能创建更通用的分区,例如将 4x4 矩阵划分为 4 个 2x2 分区。 MatrixForm 也不能进行任何类型的分区。那么,我将如何以编程方式显示这样的分区矩阵呢?我想保留 MatrixForm 仅充当包装器而不影响后续评估的能力,但这并不是绝对必要的。我怀疑这会涉及使用Grid
,但我还没有尝试过。
I know that using the Insert menu, you can create a matrix with vertical and horizontal lines, but not a more generic partition, such as dividing a 4x4 matrix into 4 2x2 partitions. Nor, can MatrixForm
do any sort of partitioning. So, how would I go about programmatically displaying such a partitioned matrix? I would like to retain the ability of MatrixForm
to act only as a wrapper and not affect subsequent evaluations, but it is not strictly necessary. I suspect this would involve using a Grid
, but I haven't tried it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在尝试让
Interpretation
放弃显示的表单并在后续行中使用矩阵时尝试了太长时间后,我放弃了,只是制作了一个几乎与 MatrixForm完全相同的包装器/代码>。这真的很快,因为它是对这个问题的简单修改。
然后后缀命令
//pMatrixForm[#, 3, 3]&
将给出所请求的 4x4 矩阵的 2x2 分区。将 pMatrixForm 的默认设置从无分区更改为中央分区可能很有用。这并不难。After playing around for far too long trying to make
Interpretation
drop the displayed form and use the matrix when used in subsequent lines, I gave up and just made a wrapper that acts almost exactly likeMatrixForm
. This was really quick as it was a simple modification of this question.Then the postfix command
//pMatrixForm[#, 3, 3]&
will give the requested 2x2 partitioning of a 4x4 matrix. It maybe useful to change the defaults ofpMatrixForm
from no partitions to central partitions. This would not be hard.这就是我想出的办法。对于矩阵 M:
构造两个 True/False 值列表(True 表示需要分隔符的位置),它们采用两个参数;第一个是矩阵,第二个是分隔符位置列表。
现在,使用
Grid[]
的分区视图是通过使用Dividers
创建的:这需要三个参数;第一个是矩阵,第二个是列分隔符的位置列表,第三个是行分隔符的值列表。
为了让它很好地显示,你只需将它包裹在小括号中并使用 MatrixForm:
它会执行你提到的 2by2 分区。
So this is what I came up with. For a matrix M:
you construct two list of True/False values (with True for places where you want separators) that take two arguments; first the matrix and second a list of positions for separators.
Now the partitioned view using
Grid[]
is made with the use ofDividers
:This takes three arguments; first the matrix, second the list of positions for column dividers, and third the list of values for row dividers.
In order for it to display nicely you just wrap it in brakets and use MatrixForm:
Which does the 2by2 partitioning you mentioned.