<aside> <img src="/icons/list_gray.svg" alt="/icons/list_gray.svg" width="40px" />
Table of Contents
</aside>
To understand the cofactor matrix, we first need to introduce the concept of a minor.

For a square matrix $A$

Simple Example : $2{\times}2$ Matrix
Let's find the minor matrix of a $2{\times}2$ matrix
$$ A = \begin{bmatrix} 3 & 1\\ 2 & 4 \end{bmatrix} $$
For $M_{11}$, we remove row $n$ and column $n$ and find the determinant:
Therefore, the minor matrix without ($i$,$j$) is
$$ M = \begin{bmatrix} 4 & 2\\ 1 & 3 \end{bmatrix} $$
Advanced Example : $3{\times}3$ Matrix
Let's find the minor matrix of a $3{\times}3$ matrix
$$ A = \begin{bmatrix} 2 & 1 & 3\\ 0 & 4 & -1\\ 5 & 2 & 2 \end{bmatrix} $$
For example, to find $M_{11}$, we remove the first row and first column:
$$ M_{11} = \det\begin{bmatrix} 4 & -1\\ 2 & 2 \end{bmatrix} = (4 \times 2) - (-1 \times 2) = 10 $$
Following this process for all elements, we get the minor matrix.
$$ M = \begin{bmatrix} 10 & -10 & 8\\ 7 & -1 & -9\\ 5 & 5 & 7 \end{bmatrix} $$
<aside> <img src="/icons/info-alternate_blue.svg" alt="/icons/info-alternate_blue.svg" width="40px" />
What’s Cofactor?
The cofactor $C_{ij}$ is calculated by multiplying the minor $M_{ij}$ by a sign factor.
$$ C_{ij} = (-1)^{i+j} \cdot \det[M_{ij}] $$
The sign alternates depending on the position $(i,j)$ in the matrix.
$$ \begin{bmatrix}
$$

Cofactor matrix is formed by replacing each element $A_{ij}$ of a square matrix $A$ with its corresponding cofactor $C_{ij}$.
For an $n{×}n$ matrix $A$, the cofactor matrix is denoted as it.
$$ C_A = [C_{ij}] $$
Example
Here is $4{\times}4$ matrix $A$
$$ A = \begin{bmatrix} 2 & -1 & 3 & 0\\ 1 & 4 & -2 & 5\\ 0 & 2 & 1 & 3\\ 3 & -3 & 2 & 1 \end{bmatrix} $$
For $C_{11}$, we first find the minor by calculating the determinant of the $3{\times}3$ matrix after removing.
$$ M_{11} = \det\begin{bmatrix} 4 & -2 & 5\\ 2 & 1 & 3\\ -3 & 2 & 1 \end{bmatrix} = 37 $$
Continuing this process for all elements, we get the minor matrix.
$$ M = \begin{bmatrix} 37 & -38 & 17 & 31\\ -28 & 17 & 13 & -7\\ -45 & 18 & 24 & -33\\ 5 & -31 & 7 & 23 \end{bmatrix} $$
Notice how the signs alternate according to the position ($i,j$).
$$ \begin{bmatrix}
Following this process for applying the appropriate signs (+, -)
$$ C_A = \begin{bmatrix} 37 & 38 & 17 & -31\\ 28 & 17 & -13 & -7\\ -45 & -18 & 24 & 33\\ -5 & -31 & -7 & 23 \end{bmatrix} $$
Adjoint matrix is defined as the transpose of the cofactor matrix.
$$ \text{adj}(A) = C_A^T $$
Example
Here is $4{\times}4$ matrix $A$.
$$ A = \begin{bmatrix} 2 & -1 & 3 & 0\\ 1 & 4 & -2 & 5\\ 0 & 2 & 1 & 3\\ 3 & -3 & 2 & 1 \end{bmatrix} $$
Here is the cofactor matrix of matrix $A$.
$$ C_A = \begin{bmatrix} 37 & 38 & 17 & -31\\ 28 & 17 & -13 & -7\\ -45 & -18 & 24 & 33\\ -5 & -31 & -7 & 23 \end{bmatrix} $$
$$ \text{adj}(A) = C_A^T = \begin{bmatrix} 37 & 28 & -45 & -5\\ 38 & 17 & -18 & -31\\ 17 & -13 & 24 & -7\\ -31 & -7 & 33 & 23 \end{bmatrix} $$
| --- | --- | --- |
Python makes it easy to calculate matrix minors, cofactors, adjoints. Let's implement each concept using the NumPy.
Get Minor Matrix