Rank of matrix
k = rank(A)
k = rank(A,tol)
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,
ans = 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
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.
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
ans = 4
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.
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
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
Usage notes and limitations:
Code generation does not support sparse matrix inputs for this function.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).