10
$\begingroup$

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: enter image description here

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 /@ # &
$\endgroup$
4
  • 5
    $\begingroup$ Perhaps Diagonal @ Minors[mat, k]? $\endgroup$
    – Carl Woll
    Commented Aug 18, 2017 at 17:01
  • 1
    $\begingroup$ Diagonal@Map[Reverse, Minors[mat, k, Identity], {0, 1}] // MatrixForm /@ # & $\endgroup$
    – kglr
    Commented Aug 18, 2017 at 17:04
  • $\begingroup$ @kglr Thanks for the answer but is this in general. What if the matrix is a 4X4 measurement . $\endgroup$ Commented Aug 18, 2017 at 17:14
  • $\begingroup$ @kglr Thank you very much. This gives the exact result in general. $\endgroup$ Commented Aug 18, 2017 at 17:24

3 Answers 3

9
$\begingroup$

To get the principal submatrices:

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

enter image description here

For the principal minors

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

enter image description here

$\endgroup$
3
  • $\begingroup$ What is the & /@ {1, 2} for? $\endgroup$
    – AzJ
    Commented Jan 25, 2018 at 19:46
  • 2
    $\begingroup$ @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]}`. ... $\endgroup$
    – kglr
    Commented Jan 25, 2018 at 20:34
  • 1
    $\begingroup$ ... Please see the doc pages on for details on of esoteric symbols such as Function (&), Slot (#) and Map $\endgroup$
    – kglr
    Commented Jan 25, 2018 at 20:35
6
$\begingroup$

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]
$\endgroup$
2
$\begingroup$

@Hvjurthuk's answer can be rewritten in the functional style as:

PrincipalMinors[mat_?SquareMatrixQ, size_Integer] /; 
  0 < size \[LessSlantEqual] Length[mat] := 
 Extract[mat, 
  ConstantArray[Subsets[Range[Length[mat]], {size}], 2]\[Transpose], 
  Det]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.