# 使用Mathematica自动显示矩阵结构

`(A = {{1, 2 + 3 I}, {2 - 3 I, 4}}) // StructureForm`

`{{a, b}, {Conjugate[b], c}}`

`{{a, b + c I}, {b - c I, d}}`

```StructureForm[M_?MatrixQ] :=
MatrixForm @ Module[
{pos, chars},
pos = Reap[
Map[Sow[Position[M, #1], #1] &, M, {2}], _,
Union[Flatten[#2, 1]] &
][[2]];  (* establishes equality relationship *)
chars = CharacterRange["a", "z"][[;; Length @ pos ]];
]```

`StructureForm @ {{1, 2}, {2, 3}} == {{a, b}, {b, c}}`

```ClearAll@relationship
relationship[a_ -> sA_, b_ -> sB_] /; b == a := b -> sA
relationship[a_ -> sA_, b_ -> sB_] /; b == -a := b -> -sA
relationship[a_ -> sA_, b_ -> sB_] /; b == Conjugate[a] := b -> SuperStar[sA]
relationship[a_ -> sA_, b_ -> sB_] /; b == -Conjugate[a] := b -> -SuperStar[sA]
relationship[_, _] := Sequence[]```

```ClearAll@structureForm
structureForm[matrix_?MatrixQ] :=
Module[{values, rules, pairs, inferences}
, values = matrix // Flatten // DeleteDuplicates
; rules = Thread[Rule[values, CharacterRange["a", "z"][[;; Length@values]]]]
; pairs = rules[[#]]& /@ Select[Tuples[Range[Length@values], 2], #[[1]] < #[[2]]&]
; inferences = relationship @@@ pairs
; matrix /. inferences ~Join~ rules
]```

```In[31]:= structureForm @ {{1, 2 + 3 I}, {2 - 3 I, 4}}

Out[31]= {{"a", "b"}, {SuperStar["b"], "d"}}

In[32]:= \$m = a + b I /. a | b :> RandomInteger[{-2, 2}, {10, 10}];
\$m // MatrixForm
\$m // structureForm // MatrixForm```