rank
Rank of a matrix: the number of singular values above a tolerance.
Category: Mathematics > Linear Algebra
Syntax
r = rank(A)
Returns the rank using the default tolerance.
r = rank(A, tol)
Counts singular values larger than tol.
Description
The rank is the number of linearly independent columns (equivalently rows). Numerically it is estimated from the singular values, since rounding makes an exactly zero value rare: values below the tolerance are treated as zero.
A full-rank square matrix is invertible. magic(4), for example, has rank 3, which is why inv(magic(4)) warns that the matrix is close to singular.
Input arguments
A- Numeric matrix.
tol- Nonnegative scalar threshold. Defaults to
max(size(A)) * eps(max(svd(A))).
Output arguments
r- Nonnegative integer, at most
min(size(A)).
Example
Dependent rows
rank([1 2; 2 4])
rank(magic(4))
rank(eye(3))
Output
ans = 1
ans = 3
ans = 3