Given a square matrix of order n\times n, the cofactor matrix is the matrix whose entries consists of the cofactors of the matrix. To find the cofactor matrix, we first calculate the minors M_{ij}, by calculating the determinant of the matrix obtained by deleting the i^{th} row and the j^{th} column. Then the cofactors are quantities that can be calculated using the formula,

C_{ij} = (-1)^{i+j}M_{ij} \text{ where }1\leq i,j \leq nThen the cofactor matrix is the matrix whose ij^{th} entry is C_{ij}. We now look at some examples of calculating cofactors of some matrices.

**Example 1:**

Consider the matrix A = \begin{bmatrix} 3 & 2 & 5\\ 8 & 5 & 3\\ 7 & 2 & 0 \end{bmatrix}.

We calculate all of the cofactors of the 3\times 3 matrix by using the above formula as follows,

C_{11} = \left(-1\right)^{1 + 1} \left|\begin{array}{cc}5 & 3\\2 & 0\end{array}\right| = -6 C_{12} = \left(-1\right)^{1 + 2} \left|\begin{array}{cc}8 & 3\\7 & 0\end{array}\right| = 21 C_{13} = \left(-1\right)^{1 + 3} \left|\begin{array}{cc}8 & 5\\7 & 2\end{array}\right| = -19 C_{21} = \left(-1\right)^{2 + 1} \left|\begin{array}{cc}2 & 5\\2 & 0\end{array}\right| = 10 C_{22} = \left(-1\right)^{2 + 2} \left|\begin{array}{cc}3 & 5\\7 & 0\end{array}\right| = -35 C_{23} = \left(-1\right)^{2 + 3} \left|\begin{array}{cc}3 & 2\\7 & 2\end{array}\right| = 8 C_{31} = \left(-1\right)^{3 + 1} \left|\begin{array}{cc}2 & 5\\5 & 3\end{array}\right| = -19 C_{32} = \left(-1\right)^{3 + 2} \left|\begin{array}{cc}3 & 5\\8 & 3\end{array}\right| = 31 C_{33} = \left(-1\right)^{3 + 3} \left|\begin{array}{cc}3 & 2\\8 & 5\end{array}\right| = -1The cofactor matrix is \begin{bmatrix} -6 & 21 & -19\\ 10 & -35 & 8\\ -19 & 31 & -1 \end{bmatrix}.

**Example 2:**

Consider the matrix A = \begin{bmatrix} 5 & 7\\ 9 & 2 \end{bmatrix}.

We calculate the cofactors of the 2\times 2 matrix by using the formula C_{ij} = (-1)^{i+j}M_{ij},

C_{11} = \left(-1\right)^{1 + 1} \left|\begin{array}{c}2\end{array}\right| = 2 C_{12} = \left(-1\right)^{1 + 2} \left|\begin{array}{c}9\end{array}\right| = -9 C_{21} = \left(-1\right)^{2 + 1} \left|\begin{array}{c}7\end{array}\right| = -7 C_{22} = \left(-1\right)^{2 + 2} \left|\begin{array}{c}5\end{array}\right| = 5The cofactor matrix is \begin{bmatrix} 2 & -9\\ -7 & 5 \end{bmatrix}.

**Use of Cofactor Matrix:**

We can use the cofactors to calculate the inverse of a matrix as follows:

- Given a square matrix A, we first calculate the cofactor matrix C.
- We then take the transpose of the matrix C.
- We divide the matrix obtained in Step 2 by the determinant of A. The resulting matrix is the inverse of the original matrix A. It is denoted as A^{-1} and we have that AA^{-1}=I.