RANK Calculate the Rank of a Matrix

Section: Array Generation and Manipulations

Usage

Returns the rank of a matrix. There are two ways to use the rank function is
   y = rank(A,tol)

where tol is the tolerance to use when computing the rank. The second form is

   y = rank(A)

in which case the tolerance tol is chosen as

   tol = max(size(A))*max(s)*eps,

where s is the vector of singular values of A. The rank is computed using the singular value decomposition svd.

Examples

Some examples of matrix rank calculations
--> rank([1,3,2;4,5,6])
ans = 
  <int32>  - size: [1 1]
 2  
--> rank([1,2,3;2,4,6])
ans = 
  <int32>  - size: [1 1]
 1  

Here we construct an ill-conditioned matrix, and show the use of the tol argument.

--> A = [1,0;0,eps/2]
A = 
  <double>  - size: [2 2]
 
Columns 1 to 2
 1.0000000000000000e+00  0.0000000000000000e+00  
 0.0000000000000000e+00  1.1102230246251565e-16  
--> rank(A)
ans = 
  <int32>  - size: [1 1]
 1  
--> rank(A,eps/8)
ans = 
  <int32>  - size: [1 1]
 2