MATLAB code for rank of a matrix

Description

Consider the column vectors

v1 = [1 ; 1 ; 1 ; 1 ; 1];
v2 = [0 ; 0 ; 0 ; 0 ; 1];
v3 = [1 ; 2 ; 2 ; 2 ; 2];

and a matrix constructed from these vectors

A = [v1 v1*2 v1*3 v1*4 v2 v2+v1 v3]
A =
1 2 3 4 0 1 1
1 2 3 4 0 1 2
1 2 3 4 0 1 2
1 2 3 4 0 1 2
1 2 3 4 1 2 2

These vectors are linearly independent from each other, which you may verify on your own. The matrix, A, has dimensions

size(A)
ans =
5 7

and rank

rank(A)
ans =
3

The rank of a matrix is the number of linearly independent vectors needed to represent it. It should be relatively clear that in this case it should be 3 because of the way A was constructed.

Matrices that have a rank lower than their smallest dimension are said to be rank deficient. Matrices with a rank equal to their smallest dimension are said to be full rank.

Another way to think about rank deficient matrices is that they contain redundant information. Vectors resulting from multiplication by a constant, or from addition of two vectors don’t contain new information.

E.g. instead of sending someone all of the numbers in A, you can send them the three linearly independent vectors in A, and the rules for consructing A. The essence of SVD is to find these rules, when only A is known.

 

 Addition of noise

Now let’s de ne matrix with small random numbers. This is a simulation of noise, which is present in any experimental data set.

% Seed rng with a constant so the numbers come out the same each time the code is run.

rng(1);

N = (rand(size(A))-0.5).*0.2

N =
-0.0166 -0.0815 -0.0162 0.0341 0.0601 0.0789 -0.0803
0.0441 -0.0627 0.0370 -0.0165 0.0937 -0.0830 -0.0158
-0.1000 -0.0309 -0.0591 0.0117 -0.0373 -0.0922 0.0916
-0.0395 -0.0206 0.0756 -0.0719 0.0385 -0.0660 0.0066
-0.0706 0.0078 -0.0945 -0.0604 0.0753 0.0756 0.0384

What happens when a small amount of noise is added to a rank de cient matrix?

rank(A+N)

ans =
5

We see that addition of noise makes the matrix full rank.

This fact is important when analysing a real experimental data set, which will always contain noise.

https://www.mathworks.com/help/matlab/ref/rank.html

Reviews

There are no reviews yet.

Be the first to review “MATLAB code for rank of a matrix”
Category: