5.3. Matrix Determinant#

The determinant is a scalar value that can be computed from a square matrix. For an \(n \times n\) matrix \(A\), we write the determinant as \(\det(A)\) or \(|A|\).

5.3.1. Properties#

The determinant tells us whether a matrix is invertible. If \(\det(A) = 0\), then matrix \(A\) is singular and has no inverse. If \(\det(A) \neq 0\), then matrix \(A\) is invertible.

Formula for 2×2 Matrix

For a \(2 \times 2\) matrix, the determinant formula is

(5.20)#\[\begin{equation} \det\begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc. \end{equation}\]

Formula for 3×3 Matrix*

For a \(3 \times 3\) matrix, we use cofactor expansion along the first row

(5.21)#\[\begin{equation} \det\begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} = a_{11}(a_{22}a_{33} - a_{23}a_{32}) - a_{12}(a_{21}a_{33} - a_{23}a_{31}) + a_{13}(a_{21}a_{32} - a_{22}a_{31}) \end{equation}\]

Examples

Consider the matrix

(5.22)#\[\begin{equation} A = \begin{bmatrix} 2 & 1 & 3 \\ 0 & 4 & 1 \\ 5 & 2 & 1 \end{bmatrix} \end{equation}\]

Compute the determinant using cofactor expansion along the first row.

(5.23)#\[\begin{equation} \det(A) = 2\begin{vmatrix} 4 & 1 \\ 2 & 1 \end{vmatrix} - 1\begin{vmatrix} 0 & 1 \\ 5 & 1 \end{vmatrix} + 3\begin{vmatrix} 0 & 4 \\ 5 & 2 \end{vmatrix} \end{equation}\]

Evaluate each \(2 \times 2\) determinant.

(5.24)#\[\begin{equation} \begin{vmatrix} 4 & 1 \\ 2 & 1 \end{vmatrix} = (4)(1) - (1)(2) = 4 - 2 = 2 \end{equation}\]
(5.25)#\[\begin{equation} \begin{vmatrix} 0 & 1 \\ 5 & 1 \end{vmatrix} = (0)(1) - (1)(5) = 0 - 5 = -5 \end{equation}\]
(5.26)#\[\begin{equation} \begin{vmatrix} 0 & 4 \\ 5 & 2 \end{vmatrix} = (0)(2) - (4)(5) = 0 - 20 = -20 \end{equation}\]

Substituting back into our expansion gives us

(5.27)#\[\begin{equation} \det(A) = 2(2) - 1(-5) + 3(-20) = 4 + 5 - 60 = -51. \end{equation}\]

Therefore \(\det(A) = -51\). Since the determinant is not zero, matrix \(A\) is invertible.

Below is the NumPy code to verify the above worked example.

import numpy as np

A = np.array([
    [2, 1, 3],
    [0, 4, 1],
    [5, 2, 1]
])

det_A = np.linalg.det(A)
print("The determinant of A, via NumPy is:", det_A)
The determinant of A, via NumPy is: -51.0

5.3.2. Laplace Expansion#

Laplace expansion (also called cofactor expansion) is a method for computing the determinant of a square matrix by expanding along any row or column.

For an \(n \times n\) matrix \(A\), the determinant can be computed by expanding along row \(i\) or column \(j\).

Expansion along row \(i\):

(5.28)#\[\begin{equation} \det(A) = \sum_{j=1}^{n} a_{ij} C_{ij} = \sum_{j=1}^{n} a_{ij} (-1)^{i+j} M_{ij} \end{equation}\]

Expansion along column \(j\):

(5.29)#\[\begin{equation} \det(A) = \sum_{i=1}^{n} a_{ij} C_{ij} = \sum_{i=1}^{n} a_{ij} (-1)^{i+j} M_{ij} \end{equation}\]

where \(C_{ij}\) is the cofactor and \(M_{ij}\) is the minor.

The minor \(M_{ij}\) is the determinant of the \((n-1) \times (n-1)\) submatrix obtained by deleting row \(i\) and column \(j\) from matrix \(A\).

The cofactor \(C_{ij}\) is the signed minor

(5.30)#\[\begin{equation} C_{ij} = (-1)^{i+j} M_{ij} \end{equation}\]

The sign pattern \((-1)^{i+j}\) creates a checkerboard pattern of positive and negative signs starting with positive in the top-left corner.

For a \(3 \times 3\) matrix, the sign pattern is

(5.31)#\[\begin{equation} \begin{pmatrix} + & - & + \\ - & + & - \\ + & - & + \end{pmatrix} \end{equation}\]

Example: 3×3 Matrix

Consider the matrix

(5.32)#\[\begin{equation} A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \end{equation}\]

We expand along the first row

(5.33)#\[\begin{equation} \det(A) = a_{11}C_{11} + a_{12}C_{12} + a_{13}C_{13} \end{equation}\]

The cofactors are

(5.34)#\[\begin{equation} C_{11} = (-1)^{1+1} M_{11} = (+1) \begin{vmatrix} 5 & 6 \\ 8 & 9 \end{vmatrix} = 5 \cdot 9 - 6 \cdot 8 = 45 - 48 = -3 \end{equation}\]
(5.35)#\[\begin{equation} C_{12} = (-1)^{1+2} M_{12} = (-1) \begin{vmatrix} 4 & 6 \\ 7 & 9 \end{vmatrix} = -(4 \cdot 9 - 6 \cdot 7) = -(36 - 42) = -(-6) = 6 \end{equation}\]
(5.36)#\[\begin{equation} C_{13} = (-1)^{1+3} M_{13} = (+1) \begin{vmatrix} 4 & 5 \\ 7 & 8 \end{vmatrix} = 4 \cdot 8 - 5 \cdot 7 = 32 - 35 = -3 \end{equation}\]

Therefore

(5.37)#\[\begin{equation} \det(A) = 1(-3) + 2(6) + 3(-3) = -3 + 12 - 9 = 0 \end{equation}\]

5.3.3. Alternative Expansion#

We can also expand along column 1

(5.38)#\[\begin{equation} \det(A) = a_{11}C_{11} + a_{21}C_{21} + a_{31}C_{31} \end{equation}\]

The cofactors are

(5.39)#\[\begin{equation} C_{21} = (-1)^{2+1} M_{21} = (-1) \begin{vmatrix} 2 & 3 \\ 8 & 9 \end{vmatrix} = -(2 \cdot 9 - 3 \cdot 8) = -(18 - 24) = 6 \end{equation}\]
(5.40)#\[\begin{equation} C_{31} = (-1)^{3+1} M_{31} = (+1) \begin{vmatrix} 2 & 3 \\ 5 & 6 \end{vmatrix} = 2 \cdot 6 - 3 \cdot 5 = 12 - 15 = -3 \end{equation}\]

Therefore

(5.41)#\[\begin{equation} \det(A) = 1(-3) + 4(6) + 7(-3) = -3 + 24 - 21 = 0 \end{equation}\]

Both expansions give the same result, confirming that \(\det(A) = 0\).

5.3.4. Example: 3×3 Matrix#

Consider the matrix

(5.42)#\[\begin{equation} A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \end{equation}\]

We expand along the first row

(5.43)#\[\begin{equation} \det(A) = a_{11}C_{11} + a_{12}C_{12} + a_{13}C_{13} \end{equation}\]

The cofactors are

(5.44)#\[\begin{equation} C_{11} = (-1)^{1+1} M_{11} = (+1) \begin{vmatrix} 5 & 6 \\ 8 & 9 \end{vmatrix} = 5 \cdot 9 - 6 \cdot 8 = 45 - 48 = -3 \end{equation}\]
(5.45)#\[\begin{equation} C_{12} = (-1)^{1+2} M_{12} = (-1) \begin{vmatrix} 4 & 6 \\ 7 & 9 \end{vmatrix} = -(4 \cdot 9 - 6 \cdot 7) = -(36 - 42) = -(-6) = 6 \end{equation}\]
(5.46)#\[\begin{equation} C_{13} = (-1)^{1+3} M_{13} = (+1) \begin{vmatrix} 4 & 5 \\ 7 & 8 \end{vmatrix} = 4 \cdot 8 - 5 \cdot 7 = 32 - 35 = -3 \end{equation}\]

Therefore

(5.47)#\[\begin{equation} \det(A) = 1(-3) + 2(6) + 3(-3) = -3 + 12 - 9 = 0 \end{equation}\]

An alternative route is to expand along column 1,

(5.48)#\[\begin{equation} \det(A) = a_{11}C_{11} + a_{21}C_{21} + a_{31}C_{31}. \end{equation}\]

The cofactors are

(5.49)#\[\begin{equation} C_{21} = (-1)^{2+1} M_{21} = (-1) \begin{vmatrix} 2 & 3 \\ 8 & 9 \end{vmatrix} = -(2 \cdot 9 - 3 \cdot 8) = -(18 - 24) = 6 \end{equation}\]
(5.50)#\[\begin{equation} C_{31} = (-1)^{3+1} M_{31} = (+1) \begin{vmatrix} 2 & 3 \\ 5 & 6 \end{vmatrix} = 2 \cdot 6 - 3 \cdot 5 = 12 - 15 = -3 \end{equation}\]

Therefore

(5.51)#\[\begin{equation} \det(A) = 1(-3) + 4(6) + 7(-3) = -3 + 24 - 21 = 0 \end{equation}\]

We can check the result using NumPy, see code below.

A = np.array([[1, 2, 3],
              [4, 5, 6],
              [7, 8, 9]])

print("The determinant of A", np.linalg.det(A))
The determinant of A 0.0