# Are compound matrices implemented in mathematica?

Compound matrices are matrices whose entries are all the minors of a given size of another matrix.

https://en.wikipedia.org/wiki/Compound_matrix

They are probably not too hard to write by the user, but maybe I am lucky and they are already implemented in mathematica ? Thanks :)

• Minors does this for square matrices. It was recently noticed that we did not extend to rectangular, so we added support for that to a future release. Jan 8 at 16:44
• @DanielLichtblau Please correct me, but at least in versions 12.0.0 and 13.0.0, Minors seems to give sensible results for rectangular matrices as well? Jan 14 at 14:15
• @Hausdorff Not that I can see: In[209]:= Minors[Array[a, {2, 3}]] During evaluation of In[209]:= Minors::matsq: Argument {{a[1,1],a[1,2],a[1,3]},{a[2,1],a[2,2],a[2,3]}} at position 1 is not a non-empty square matrix. Out[209]= Minors[{{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2], a[2, 3]}}] Jan 17 at 21:04
• @DanielLichtblau It does do it if you specify the order of the minor matrix, e.g. Minors[Array[a, {2, 3}], 2] Jan 17 at 23:17
• @DanielLichtblau And it seems you would need to specify the order to make the minor matrix well-defined in the rectangular case. In your example you could image dropping either a column and row each time (leading to 1×1 "determinants"), or only a column (leading to 2×2 determinants). I don't see which would be the natural extension of the square case. Plus, for the compound matrix, you have to to specify the minor order anyways. Jan 18 at 0:06

I don't think that they are built-in, but they are easy enough to implement:

CompoundMatrix[A_?MatrixQ, k_Integer] := Module[{m, n, p, q, i, j},
{m, n} = Dimensions[A];
p = Subsets[Range[1, m], {k}];
q = Subsets[Range[1, n], {k}];
Table[Det[A[[i, j]]], {i, p}, {j, q}]
];


Using the elementary example from the linked Wikipedia article:

A = Partition[Range[1, 12], 4];
CompoundMatrix[A, 2]


{{-4, -8, -12, -4, -8, -4}, {-8, -16, -24, -8, -16, -8}, {-4, -8, -12, -4, -8, -4}}

• The variables i, j used for Table should also be made local in Module to avoid bugs, such as for example here Jan 14 at 14:39
• @Hausdorff The variables i and j are scoped by Table itself. This should not be the reason for any bugs. Jan 14 at 17:22
• @Hausdorff The documentation of Table says: "Table effectively uses Block to localize values or variables." Jan 14 at 17:26
• Oh wow, you're right. This never occured to me. Thanks for the lesson! =) Jan 14 at 21:01
• No worries, this is also the first time I have stumbled over this :) Jan 14 at 21:06