5.5. Matrix Rank#
The rank of a matrix is the number of linearly independent rows or columns.
The rank of a matrix \(A\) is denoted as \(\text{rank}(A)\) or \(r(A)\).
The rank of an \(m \times n\) matrix is always less than or equal to both \(m\) and \(n\): \(\text{rank}(A) \leq \min(m, n)\)
The rank of a zero matrix (all elements are zero) is 0.
A square \(n \times n\) matrix has full rank (rank \(n\)) if and only if it is invertible (non-singular), its determinant is non-zero, and all its rows and columns are linearly independent. The following are equivalent:
Full Rank
\begin{equation} \text{rank}(A) = n \end{equation}Invertible (Non-Singular)
\begin{equation} A^{-1} \text{ exists} \end{equation}Non-Zero Determinant
\begin{equation} \det(A) \neq 0 \end{equation}Linearly Independent Rows and Columns
Rows of \(A\) are linearly independent
Columns of \(A\) are linearly independent
The row rank (maximum number of linearly independent rows) is always equal to the column rank (maximum number of linearly independent columns).
Elementary row (or column) operations do not change the rank of a matrix.
5.5.1. Gaussian Elimination to Find the Rank#
Transform the matrix into its row echelon form (REF) or reduced row echelon form (RREF) using elementary row operations.
The rank of the matrix is the number of non-zero rows in its REF or RREF. A non-zero row is a row that contains at least one non-zero element.
Example
Step 1: Eliminate elements below the first pivot (the element in the first row and first column).
\(R_2 = R_2 - 2R_1\): Subtract 2 times the first row from the second row.
(5.63)#\[\begin{equation} \begin{bmatrix} 1 & 2 & 3 \\ 2 - 2(1) & 5 - 2(2) & 7 - 2(3) \\ 3 & 7 & 10 \end{bmatrix} = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 3 & 7 & 10 \end{bmatrix} \end{equation} \]\(R_3 = R_3 - 3R_1\): Subtract 3 times the first row from the third row.
(5.64)#\[\begin{equation} \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 3 - 3(1) & 7 - 3(2) & 10 - 3(3) \end{bmatrix} = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 0 & 1 & 1 \end{bmatrix} \end{equation} \]
Step 2: Eliminate elements below the second pivot (the element in the second row and second column).
\(R_3 = R_3 - 1R_2\): Subtract the second row from the third row.
(5.65)#\[\begin{equation} \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 0 - 0 & 1 - 1 & 1 - 1 \end{bmatrix} = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \end{bmatrix} \end{equation} \]
Step 3: Identify the number of non-zero rows.
The matrix is now in row echelon form. The non-zero rows are:
\([1 \quad 2 \quad 3]\)
\([0 \quad 1 \quad 1]\)
There are two non-zero rows; therefore, the rank is 2.
Here is the example in NumPy.
import numpy as np
import sympy as sym
# NumPy rank
A = np.array([[1,2,3],[2,5,7], [3, 7,10]])
np.linalg.matrix_rank(A)
np.int64(2)
Here is the example in SymPy. SymPy can get the matrix in reduced row echelon form with the command Matrix.rref() and the rank with the command Matrix.rank().
A = sym.Matrix([[1,2,3],[2,5,7], [3, 7,10]])
A
# SymPy reduced row echelon form
A.rref()
(Matrix([
[1, 0, 1],
[0, 1, 1],
[0, 0, 0]]),
(0, 1))
# Sympy rank
A.rank()
2
# A few more NumPy Examples
A = np.array([[1,0,1],[0,0,1],[0, 0, 2]])
np.linalg.matrix_rank(A)
np.int64(2)
A = np.array([[10, 8, 9], [-3, 4, 0],[2, 60, -100]])
np.linalg.matrix_rank(A)
np.int64(3)