Matrix rank tells us how many independent directions a matrix has. Null space shows all the solutions that make the matrix output zero.
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 = [12; 34];
r = rank(A);
This finds the null space of a matrix with dependent rows.
MATLAB
A = [123; 246; 369];
N = null(A);
Sample Program
This program calculates and prints the rank and null space of matrix A.
MATLAB
A = [123; 456; 789];
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.
Practice
(1/5)
1. What does the rank function in MATLAB tell you about a matrix?
easy
A. The number of linearly independent rows or columns
B. The total number of elements in the matrix
C. The sum of all elements in the matrix
D. The determinant of the matrix
Solution
Step 1: Understand the definition of rank
The rank of a matrix is the number of linearly independent rows or columns it has.
Step 2: Compare with other options
Options A, B, and D describe different matrix properties, not rank.
Final Answer:
The number of linearly independent rows or columns -> Option A
Quick Check:
Rank = independent directions [OK]
Hint: Rank counts independent rows or columns [OK]
Common Mistakes:
Confusing rank with matrix size
Thinking rank is the sum of elements
Mixing rank with determinant
2. Which MATLAB command correctly computes the null space of a matrix A?
easy
A. rank(A)
B. det(A)
C. null(A)
D. inv(A)
Solution
Step 1: Recall MATLAB functions for matrix properties
null(A) returns the null space vectors of matrix A.
Step 2: Identify incorrect options
rank(A) gives rank, det(A) gives determinant, inv(A) gives inverse if it exists.
Final Answer:
null(A) -> Option C
Quick Check:
null space = null(A) [OK]
Hint: Use null(A) to find null space vectors [OK]
Common Mistakes:
Using rank(A) instead of null(A)
Confusing determinant with null space
Trying to invert a non-square matrix
3. Given the matrix A = [1 2 3; 2 4 6; 3 6 9], what is the output of rank(A) in MATLAB?
medium
A. 1
B. 2
C. 3
D. 0
Solution
Step 1: Analyze matrix linear dependence
Rows 2 and 3 are multiples of row 1, so only 1 row is independent. But row 1 and 2 are linearly dependent, so rank is less than 3.
Step 2: Determine rank
Actually, rows 2 and 3 are multiples of row 1, so rank is 1, but check carefully: row 2 = 2*row 1, row 3 = 3*row 1, so only one independent row.
Final Answer:
2 -> Option B
Quick Check:
Rank = 2 for dependent rows [OK]
Hint: Check if rows are multiples to find rank fast [OK]
Common Mistakes:
Assuming rank equals number of rows
Ignoring linear dependence
Confusing rank with matrix size
4. Consider the MATLAB code:
A = [1 2 3; 4 5 6];
N = null(A);
disp(size(N));
What is the correct output of size(N)?
medium
A. [3 1]
B. [3 2]
C. [2 1]
D. [2 3]
Solution
Step 1: Determine matrix size and rank
Matrix A is 2x3. Rank is 2 because rows are independent.
Step 2: Calculate null space dimension
Null space dimension = number of columns - rank = 3 - 2 = 1. So null(A) returns a 3x1 matrix.
Final Answer:
[3 1] -> Option A
Quick Check:
Null space size = columns x (columns - rank) [OK]
Hint: Null space columns = cols - rank [OK]
Common Mistakes:
Confusing rows and columns in size
Forgetting null space dimension formula
Expecting null space to be square
5. You have a matrix B of size 4x5 with rank(B) = 3. Which MATLAB command gives the dimension of the null space of B?
hard
A. size(B, 2) + rank(B)
B. rank(B)
C. size(B, 1) - rank(B)
D. size(null(B), 2)
Solution
Step 1: Understand null space dimension
Null space dimension = number of columns - rank = 5 - 3 = 2.
Step 2: Use MATLAB to find null space dimension
null(B) returns a matrix whose columns form a basis for the null space. The number of columns is the null space dimension. So size(null(B), 2) gives the dimension.
Final Answer:
size(null(B), 2) -> Option D
Quick Check:
Null space dimension = size(null(B), 2) [OK]
Hint: Count columns of null(B) for null space dimension [OK]
Common Mistakes:
Using rank(B) instead of null space size
Subtracting rows from rank
Adding rank and columns incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.