gpt4 book ai didi

wolfram-mathematica - 如何以编程方式在 Mathematica 中显示分区矩阵?

转载 作者:行者123 更新时间:2023-12-04 08:06:25 24 4
gpt4 key购买 nike

我知道使用“插入”菜单,您可以创建具有垂直和水平线的矩阵,但不能创建更通用的分区,例如将 4x4 矩阵分成 4 个 2x2 分区。 MatrixForm 也不能进行任何类型的划分。那么,我将如何以编程方式显示这样一个分区矩阵?我想保留 MatrixForm 的能力,使其仅充当包装器而不影响后续评估,但这不是绝对必要的。我怀疑这会涉及到使用 Grid,但我还没有尝试过。

最佳答案

在尝试让 Interpretation 放弃显示的形式并在后续行中使用矩阵时玩了太久之后,我放弃了,只是制作了一个包装器,其行为几乎与 矩阵形式。这真的很快,因为它是对 this question 的简单修改。 .

Clear[pMatrixForm,pMatrixFormHelper]
pMatrixForm[mat_,col_Integer,row_:{}]:=pMatrixForm[mat,{col},row]
pMatrixForm[mat_,col_,row_Integer]:=pMatrixForm[mat,col,{row}]

pMatrixFormHelper[mat_,col_,row_]:=Interpretation[MatrixForm[
{Grid[mat,Dividers->{Thread[col->True],Thread[row->True]}]}],mat]

pMatrixForm[mat_?MatrixQ,col:{___Integer}:{},row:{___Integer}:{}]:=
(CellPrint[ExpressionCell[pMatrixFormHelper[mat,col,row],
"Output",CellLabel->StringJoin["Out[",ToString[$Line],"]//pMatrixForm="]]];
Unprotect[Out];Out[$Line]=mat;Protect[Out];mat;)

然后后缀命令 //pMatrixForm[#, 3, 3]& 将给出请求的 4x4 矩阵的 2x2 分区。将 pMatrixForm 的默认值从无分区更改为中央分区可能很有用。这并不难。

关于wolfram-mathematica - 如何以编程方式在 Mathematica 中显示分区矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3978149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com