Numerical estimate of the rank of a matrix
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
numeric::rank(A) returns an integer indicating
the rank of the matrix A.
All entries of the input matrix must be numerical, i.e., they must be floating-point numbers or expressions that can be converted to floating-point numbers.
The rank of a matrix coincides with the number of non-zero singular values.
A numerical estimate of the rank is computed by counting all singular values that are larger than eps smax, where smax is the largest singular value. (All smaller singular values are regarded as round-off artifacts and treated as zero.)
The function is sensitive to the environment variable
which determines the numerical working precision.
We consider a quadratic matrix of rank 2:
A := matrix([[1, 1, I], [1, 2, 3], [2, 4, 6]]): numeric::rank(A)
Hilbert matrices have full rank. However, they are extremely
ill-conditioned and it is difficult to compute their rank numerically.
The 10×10 Hilbert
matrix has rank 10. Numerically, however, some of the singular values
are so small that they may be regarded as zero resulting in a smaller
numerical rank. In particular, with the default value
two singular values are smaller than eps smax where
the maximal singular value:
A := linalg::hilbert(10): numeric::singularvalues(A)
We specify a second argument
eps = 10-
14 to allow smaller singular values to be
regarded as non-zero. Now, the numerical rank is 10:
We consider a non-square matrix of rank 1:
A := matrix([[0, 0], [I, 1], [I, 1]]): numeric::rank(A)
We demonstrate the difference between hardware floats and software floats:
A := linalg::hilbert(15): numeric::rank(A, 10^(-20), SoftwareFloats), numeric::rank(A, 10^(-20), HardwareFloats)
Relative tolerance: regard all singular values
Compared to the
If the result cannot be computed with hardware floats, software arithmetic by the MuPAD kernel is tried.
If the current value of
There may be several reasons for hardware arithmetic to fail: