# Principal submatrix and Principal minor of a matrix

A submatrix of a matrix is obtained by deleting any collection of rows and/or columns.

For example, from the following 3-by-4 matrix, we can construct a 2-by-3 submatrix by removing row 3 and column 2:

The minors and cofactors of a matrix are found by computing the determinant of certain submatrices.

A principal submatrix is a square submatrix obtained by removing certain rows and columns. The definition varies from author to author. According to some authors, a principal submatrix is a submatrix in which the set of row indices that remain is the same as the set of column indices that remain.

For a general 3 × 3 matrix in Mathematica,

(mat = Array[Subscript[a, ##] &, {3, 3}]) // MatrixForm


$mat=\left( \begin{array}{ccc} a_{1,1} & a_{1,2} & a_{1,3} \\ a_{2,1} & a_{2,2} & a_{2,3} \\ a_{3,1} & a_{3,2} & a_{3,3} \\ \end{array} \right)$

there is one third order principal submatrix, namely mat. There are three second order principal submatrix:

$mat_{33}=\left( \begin{array}{ccc} a_{1,1} & a_{1,2} \\ a_{2,1} & a_{2,2} \\ \end{array} \right)$, formed by deleting column 3 and row 3;

$mat_{22}=\left( \begin{array}{ccc} a_{1,1} & a_{1,3} \\ a_{3,1} & a_{3,3} \\ \end{array} \right)$, formed by deleting column 2 and row 2;

$mat_{11}=\left( \begin{array}{ccc} a_{2,2} & a_{2,3} \\ a_{3,2} & a_{3,3} \\ \end{array} \right)$, formed by deleting column 1 and row 1;

And there are three first order principal submatrix:

$mat=\left( \begin{array}{ccc} a_{1,1} \\ \end{array} \right)$, formed by deleting column 2,3 and row 2,3;

$mat=\left( \begin{array}{ccc} a_{2,2} \\ \end{array} \right)$, formed by deleting column 1, 3 and row 1, 3;

$mat=\left( \begin{array}{ccc} a_{3,3} \\ \end{array} \right)$, formed by deleting column 1,2 and row 1,2;

Do you have a way to find all principal submatrix in Mathematica ?

or find the determine of all principal submatrix (principal minor) in Mathematica ?

By @klgr comment.

Diagonal@Map[Reverse, Minors[mat, k, Identity], {0, 1}] //MatrixForm /@ # &

• Perhaps Diagonal @ Minors[mat, k]? – Carl Woll Aug 18 '17 at 17:01
• Diagonal@Map[Reverse, Minors[mat, k, Identity], {0, 1}] // MatrixForm /@ # & – kglr Aug 18 '17 at 17:04
• @kglr Thanks for the answer but is this in general. What if the matrix is a 4X4 measurement . – Emad kareem Aug 18 '17 at 17:14
• @kglr Thank you very much. This gives the exact result in general. – Emad kareem Aug 18 '17 at 17:24

To get the principal submatrices:

Diagonal[Map[Reverse, Minors[mat, #, Identity], {0, 1}]] & /@ {1, 2}


For the principal minors

Diagonal[Map[Reverse, Minors[mat, #], {0, 1}]] & /@ {1, 2}


• What is the & /@ {1, 2} for? – AzJ Jan 25 '18 at 19:46
• @AzJ, the & belongs to the left part, that is, the expression is actually (Diagonal[Map[Reverse, Minors[mat, #], {0, 1}]] & ) /@ {1,2}. For a pure function (a function with unnamed arguments) foo[#]& (where foo is an instruction on what to do with the stuff #; for example, multiply it by 2 and add 1 , (1+ 3 #)&) , the expression foo[#]&/@{a,b,c} Maps foo over a list of arguments ({a, b}) , that is, it is a short hand for  {foo[a], foo[b], foo[c]}. ... – kglr Jan 25 '18 at 20:34
• ... Please see the doc pages on for details on of esoteric symbols such as Function (&), Slot (#) and Map – kglr Jan 25 '18 at 20:35

I arrived three years later but I think that the code of @klgr can be significantly improved as it computes first all the minors to take at the end just those on the diagonal. I think that the next routine works faster for the submatrices with the obvious change making it work also for the minors, of course. I also suppose for convenience that the matrix is square, the obvious change make this also work for non-square matrices.

PrincipalSubmatrices[mat_, size_] :=
Module[{choices = Subsets[Table[i, {i, 1, Length[mat]}], {size}], count,
rc, symsubmatrix, symsubmatrices}, count = choices;
symsubmatrices = {};
While[count != {}, rc = count[[1]]; symsubmatrix = mat[[rc, rc]];
symsubmatrices = Append[symsubmatrices, symsubmatrix];
count = Delete[count, 1]]; symsubmatrices]