Skip to main content

Linear Algebra with SageMath Learn math with open-source software

Section 8.3 Cofactors Matrix

The cofactor \(c_{ij}\) is computed as \(c_{ij} = (-1)^{i+j} M_{ij}\text{,}\) where \(M_{ij}\) is the minor obtained by deleting the \(i^{th}\) row and \(j^{th}\) column of \(A\text{.}\) The following computes the cofactor \(c_{12}\) using the previously computed minor \(M_{12}\text{.}\)
Given a square matrix \(A_{n \times n} = [a_{ij}]\text{,}\) its cofactors matrix \(C_{n \times n}\) is defined as \(C = [c_{ij}]\) where each entry \(c_{ij}\) is the cofactor of the entry \(a_{ij}\) in \(A\text{.}\)
We can build the cofactor matrix \(C\) by repeating the same last two steps, and varying the row and column indices \(i\) and \(j\) from \(1\) to \(n\text{.}\)

Note 8.3.1. Cofactors and 0-Based Indexing.

Recall that Sage uses \(0\)-based indexing of lists, vectors, and matrices. If we were to follow the mathematical notation with \(1\)-based indexing, where \(i\) and \(j\) vary from \(1\) to \(n\text{,}\) the formula for the cofactors entries of \(C\) would be written as:
Another valid expression while keeping \(0\)-based indexing, and \(i\) and \(j\) vary from \(0\) to \(n-1\) would be:
All these expressions are equivalent and correctly computes the cofactors entries of \(C\text{.}\)
Finally, we take the transpose of \(C\) to get the adjugate matrix.
Note that the adjugate matrix calculated in this way coincides with the one resulted from the built-in method introduced earlier, and we can verify they are indeed equal.