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{.}\)
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:
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.