Skip to main content

1.8 Rank of a Matrix

 Rank of a Matrix

The number of linearly independent columns of a matrix $A \in \mathbb{R}^{m \times n}$ equals the number of linearly independent rows and is called the  rank of $A$ and is denoted by $rk(A)$.

The rank of a matrix has some important properties:

  • $rk(A) = rk(A^T)$, i.e., the column rank equals the row rank.
  • The columns of $A \in \mathbb{R}^{m \times n}$ span a subspace $U  \subseteq \mathbb{R}^m$ with $dim(U) =rk(A)$. Later we will call this subspace the image or range. A basis of $U$ can be found by applying Gaussian elimination to $A $ to identify the pivot columns.
  • The rows of $A \in \mathbb{R}^{m \times n}$  span a subspace $W \in \mathbb{R}^n$ with $dim(W) =rk(A)$. A basis of W can be found by applying Gaussian elimination to $A^T$.
  • For all $A \in \mathbb{R}^{n \times n}$ it holds that $A$ is regular (invertible) if and only if $rk(A) = n$.
  • For all $A \in \mathbb{R}^{m \times n}$ and all $ b \in \mathbb{R}^m$ it holds that the linear equation system $Ax = b$ can be solved if and only if $ rk(A) = rk(A|b)$, where $A|b$ denotes the augmented system.
  • For $A \in \mathbb{R}^{m \times n}$ the subspace $U \subseteq \mathbb{R}^n$ of solutions for $Ax = 0$ possesses dimension $n - rk(A)$. Later, we will call this subspace the kernel or the null space.
  • A matrix $A \in \mathbb{R}^{m \times n}$ has full rank if its rank equals the largest possible rank for a matrix of the same dimensions. This means that the rank of a full-rank matrix is the lesser of the number of rows and columns, i.e.,$rk(A) = min(m, n)$. A matrix is said to be rank deficient if it does not have full rank.
Example:
$A=\displaystyle \left[\begin{matrix}1 & 0 & 1\\0 & 1 & 1\\0 & 0 & 0\end{matrix}\right]$
A has two linearly independent rows/columns so that $rk(A) = 2$.
find the rank
$A=\displaystyle \left[\begin{matrix}1 & 2 & 1\\-2 & -3 & 1\\3 & 5 & 0\end{matrix}\right]$
We can use Gaussian elimination to determine the rank
import sympy as sp
import numpy as np
row1=[1,2,1]
row2=[-2,-3,1]
row3=[3,5,0]
M = sp.Matrix((row1,row2,row3))
print("Coefficient Matrix")
display(M)
print(" Echelon Form")
display(M.echelon_form())

O/P
Coefficient Matrix
$\displaystyle \left[\begin{matrix}1 & 2 & 1\\-2 & -3 & 1\\3 & 5 & 0\end{matrix}\right]$
Echelon Form
$\displaystyle \left[\begin{matrix}1 & 2 & 1\\0 & 1 & 3\\0 & 0 & 0\end{matrix}\right]$
Here, we see that the number of linearly independent rows and columns is 2, such that $rk(A) = 2.$


An intuition for rank is to consider it the number of dimensions spanned by all of the vectors within a matrix. For example, a rank of 0 suggest all vectors span a point, a rank of 1 suggests all vectors span a line, a rank of 2 suggests all vectors span a two-dimensional plane. The rank is estimated numerically, often using a matrix decomposition method. A common approach is to use the Singular-Value Decomposition or SVD for short. NumPy provides the matrix rank() function for calculating the rank of an array. It uses the SVD method to estimate the rank. The example below demonstrates calculating the rank of a matrix with scalar values and another vector with all zero values.
# vector rank
from numpy import array
from numpy.linalg import matrix_rank
# rank
v1 = array([1,2,3])
print("v1");
print(v1)
vr1 = matrix_rank(v1)
print("Rank of v1")
print(vr1)
# zero rank
v2 = array([0,0,0,0,0])
print("v2")
print(v2)
vr2 = matrix_rank(v2)
print("Rank of v2")
print(vr2)
o/p:
v1
[1 2 3]
Rank of v1
1
v2
[0 0 0 0 0]
Rank of v2
0
# matrix rank
from numpy import array
from numpy.linalg import matrix_rank
# rank 0
M0 = array([[0,0],[0,0]])
mr0 = matrix_rank(M0)
print("M0 and Rank of M0")
print(M0)
print(mr0)
# rank 1
M1 = array([[1,2],[1,2]])
mr1 = matrix_rank(M1)
print("M1 and Rank of M1")
print(M1)
print(mr1)
# rank 2
M2 = array([[1,2],[3,4]])
mr2 = matrix_rank(M2)
print("M2 and Rank of M2")
print(M2)
print(mr2)
o/p:
M0 and Rank of M0
[[0 0]
[0 0]]
0
M1 and Rank of M1
[[1 2]
[1 2]]
1
M2 and Rank of M2
[[1 2]
[3 4]]
2

Rank and determinant using sympy

import sympy
M=sympy.Matrix([[1,2],[4,5]])
display(M)
print("determinent")
print(sympy.det(M))
print("rank")
print(sympy.Matrix.rank(M))

o/p
$\displaystyle \left[\begin{matrix}1 & 2\\4 & 5\end{matrix}\right]$
determinent 
-3 
rank 
2

Example ( University question)
Find the rank of the matrix
$A=\begin{bmatrix}
1 & 2 & 3\\
2 &3 & 4\\
3 & 5 & 7
\end{bmatrix}$
Do the elementary row operations and convert into echelon form
$R_2=R_2-2R_1$
$R_3=R_3-3R_1$
$A=\begin{bmatrix}
1 & 2 & 3\\
0 &-1 & -2\\
0 & -1 & -2
\end{bmatrix}$

$R_3=R_3-R_2$
$A=\begin{bmatrix}
1 & 2 & 3\\
0 &-1 & -2\\
0 & 0 & 0
\end{bmatrix}$

From the echelon form the number of non zero rows is 2 . So the rank is 2.

Example:




Comments

Popular posts from this blog

Mathematics for Machine Learning- CST 284 - KTU Minor Notes - Dr Binu V P

  Introduction About Me Syllabus Course Outcomes and Model Question Paper University Question Papers and Evaluation Scheme -Mathematics for Machine learning CST 284 KTU Overview of Machine Learning What is Machine Learning (video) Learn the Seven Steps in Machine Learning (video) Linear Algebra in Machine Learning Module I- Linear Algebra 1.Geometry of Linear Equations (video-Gilbert Strang) 2.Elimination with Matrices (video-Gilbert Strang) 3.Solving System of equations using Gauss Elimination Method 4.Row Echelon form and Reduced Row Echelon Form -Python Code 5.Solving system of equations Python code 6. Practice problems Gauss Elimination ( contact) 7.Finding Inverse using Gauss Jordan Elimination  (video) 8.Finding Inverse using Gauss Jordan Elimination-Python code Vectors in Machine Learning- Basics 9.Vector spaces and sub spaces 10.Linear Independence 11.Linear Independence, Basis and Dimension (video) 12.Generating set basis and span 13.Rank of a Matrix 14.Linear Mapping...

Vectors in Machine Learning

As data scientists we work with data in various formats such as text images and numerical values We often use vectors to represent data in a structured and efficient manner especially in machine learning applications In this blog post we will explore what vectors are in terms of machine learning their significance and how they are used What is a Vector? In mathematics, a vector is a mathematical object that has both magnitude and direction. In machine learning, a vector is a mathematical representation of a set of numerical values. Vectors are usually represented as arrays or lists of numbers, and each number in the list represents a specific feature or attribute of the data. For example, suppose we have a dataset of houses, and we want to predict their prices based on their features such as the number of bedrooms, the size of the house, and the location. We can represent each house as a vector, where each element of the vector represents a specific feature of the house, such as the nu...

2.14 Singular Value Decomposition

The Singular Value Decomposition ( SVD) of a matrix is a central matrix decomposition method in linear algebra.It can be applied to all matrices,not only to square matrices and it always exists.It has been referred to as the 'fundamental theorem of linear algebra'( strang 1993). SVD Theorem: Let $A^{m \times n}$ be a rectangular matrix of rank $r \in [0,min(m,n)]$. The SVD of A is a decomposition of the form. $A= U \Sigma V^T $ with an orthogonal matrix $U \in \mathbb{R}^{m \times m}$ with column vectors $u_i, i=1,\ldots,m$ and an orthogonal matrix $V \in \mathbb{R}^{n \times n}$ with column vectors $v_j, j=1,\ldots,n$.Moreover, $\Sigma$ is an $m \times n$ matrix with $\sum_{ii} = \sigma \ge 0$ and $\sigma_{ij}=0, i \ne j$. The diagonal entries $\Sigma_i=1,\ldots,r$ of $\sigma$ are called singular values . $u_i$ are called left singular vectors , and $v_j$ are called right singular vectors .By convention singular values are ordered ie; $\sigma_1 \ge \sigma_2 \ldots \sigma_r \...