Main Content

rank

Rank of matrix

Description

k = rank(A) returns the rank of matrix A.

Use sprank to determine the structural rank of a sparse matrix.

example

k = rank(A,tol) specifies a different tolerance to use in the rank computation. The rank is computed as the number of singular values of A that are larger than tol.

example

Examples

collapse all

Determine whether a matrix is full rank.

Create a 3-by-3 matrix. The values in the third column are twice as large as those in the second column.

A = [3 2 4; -1 1 2; 9 5 10]
A = 3×3

     3     2     4
    -1     1     2
     9     5    10

Calculate the rank of the matrix. If the matrix is full rank, then the rank is equal to the number of columns, size(A,2).

rank(A)
ans = 
2
size(A,2)
ans = 
3

Since the columns are linearly dependent, the matrix is rank deficient.

Calculate the rank of a matrix using a tolerance.

Create a 4-by-4 diagonal matrix. The diagonal has one small value equal to 1e-15.

A = [10 0 0 0; 0 25 0 0; 0 0 34 0; 0 0 0 1e-15]
A = 4×4

   10.0000         0         0         0
         0   25.0000         0         0
         0         0   34.0000         0
         0         0         0    0.0000

Calculate the rank of the matrix.

rank(A)
ans = 
3

The matrix is not considered to be full rank, since the default algorithm calculates the number of singular values larger than max(size(A))*eps(norm(A)). For this matrix, the small value on the diagonal is excluded since it is smaller than the tolerance.

Calculate the rank of the matrix again, but specify a tolerance of 1e-16.

rank(A,1e-16)
ans = 
4

Input Arguments

collapse all

Input matrix.

Data Types: single | double
Complex Number Support: Yes

Tolerance, specified as a scalar. See the Algorithms section for more information.

Example: rank(A,1e-5)

More About

collapse all

Rank

The number of linearly independent columns in a matrix is the rank of the matrix. The row and column rank of a matrix are always equal.

A matrix is full rank if its rank is the highest possible for a matrix of the same size, and rank deficient if it does not have full rank. The rank gives a measure of the dimension of the range or column space of the matrix, which is the collection of all linear combinations of the columns.

Algorithms

rank uses a method based on the singular value decomposition, or SVD. The SVD algorithm is more time consuming than some alternatives, but it is also the most reliable.

The rank of a matrix A is computed as the number of singular values that are larger than a tolerance. By default, the tolerance is max(size(A))*eps(norm(A)). However, you can specify a different tolerance with the command rank(A,tol).

Extended Capabilities

Version History

Introduced before R2006a