Matrix rank tells us how many independent directions a matrix has. Null space shows all the solutions that make the matrix output zero.
0
0
Matrix rank and null space in MATLAB
Introduction
To check if a system of linear equations has a unique solution.
To find all vectors that a matrix sends to zero.
To understand the dimensions of data in machine learning.
To simplify matrices by removing redundant rows or columns.
Syntax
MATLAB
r = rank(A); N = null(A);
rank(A) returns the number of independent rows or columns in matrix A.
null(A) returns a matrix whose columns form a basis for the null space of A.
Examples
This finds the rank of a 2x2 matrix A.
MATLAB
A = [1 2; 3 4]; r = rank(A);
This finds the null space of a matrix with dependent rows.
MATLAB
A = [1 2 3; 2 4 6; 3 6 9]; N = null(A);
Sample Program
This program calculates and prints the rank and null space of matrix A.
MATLAB
A = [1 2 3; 4 5 6; 7 8 9]; r = rank(A); N = null(A); fprintf('Rank of A: %d\n', r); fprintf('Null space of A:\n'); disp(N);
OutputSuccess
Important Notes
The rank is always less than or equal to the smallest dimension of the matrix.
The null space vectors are orthogonal to the row space of the matrix.
If the rank equals the number of columns, the null space contains only the zero vector.
Summary
Rank tells how many independent directions a matrix has.
Null space shows all vectors that become zero when multiplied by the matrix.
Use rank(A) and null(A) in MATLAB to find these.