({{, (RefLink[MatrixRank, paclet:ref/MatrixRank])[m]
gives the rank of the matrix m. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[MatrixRank, paclet:ref/MatrixRank]) works on both numerical and symbolic matrices.

The rank of a matrix is the number of linearly independent rows or columns.

(RefLink[MatrixRank, paclet:ref/MatrixRank])[m,(RefLink[Modulus, paclet:ref/Modulus])->n] finds the rank for integer matrices modulo n.

(RefLink[MatrixRank, paclet:ref/MatrixRank])[m,(RefLink[ZeroTest, paclet:ref/ZeroTest])->test] evaluates test[m[[i,j]]] to determine whether matrix elements are zero. The default setting is (RefLink[ZeroTest, paclet:ref/ZeroTest])->(RefLink[Automatic, paclet:ref/Automatic]).

(RefLink[MatrixRank, paclet:ref/MatrixRank])[m,(RefLink[Tolerance, paclet:ref/Tolerance])->t] gives the minimum rank with each element in a numerical matrix assumed to be correct only to within tolerance t.

(RefLink[MatrixRank, paclet:ref/MatrixRank]) works with sparse arrays.

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Find the number of linearly independent rows:

MatrixRank[{{1,2,3},{4,5,6},{7,8,9}}]

OpenersExampleSection1(Spacer1)Scope  (5)

(RefLink[MatrixRank, paclet:ref/MatrixRank]) can handle rectangular matrices:

MatrixRank[{{1,0},{3,2},{7,2},{8,1}}]

(RefLink[MatrixRank, paclet:ref/MatrixRank]) assumes all symbols to be independent:

MatrixRank[{{a,b},{c,d}}]

MatrixRank[{{a,b},{2a,2b}}]

(RefLink[MatrixRank, paclet:ref/MatrixRank]) for a machine-number matrix:

m={{1.,2.,3.},{4.,5.,6.},{7.,8.,9.}};

MatrixRank[m]

Find the matrix rank for a complex-valued matrix:

MatrixRank[{{1, I}, {I, -1}}]

Find the rank of a sparse matrix:

m=SparseArray[{Band[{1,1},{50,50}]->1,Band[{1,50},{50,1},{1,-1}]->1}];

MatrixRank[%]

ArrayPlot[m]

OpenersExampleSection2(Spacer1)Options  (2)

OpenersExampleSubsection0(Spacer1)Modulus  (1)

The rank of a matrix depends on the modulus used:

m = {{1,0,4},{2,0,3},{2,1,2}};

With ordinary arithmetic, m has the full rank of 3:

MatrixRank[m]

With arithmetic modulo 5, the rank is only 2:

MatrixRank[m,Modulus->5]

OpenersExampleSubsection1(Spacer1)Tolerance  (1)

The setting of (RefLink[Tolerance, paclet:ref/Tolerance]) can affect the estimated rank for numerical ill-conditioned matrices:

m = {{1,1,1},{0,(10^(-10)), 0},{0,0,(10^(-20))}};

In exact arithmetic, m has full rank:

MatrixRank[m]

With machine arithmetic, the default is to consider elements that are too small as zero:

MatrixRank[N[m]]

With zero tolerance, even small terms may be taken into account:

MatrixRank[N[m], Tolerance->0]

With a tolerance greater than the pivot in the middle row, the last two rows are considered zero:

MatrixRank[N[m], Tolerance->(10^(-8))]

OpenersExampleSection3(Spacer1)Applications  (2)

Most but not all random 10×10 0–1 matrices have full rank:

Table[MatrixRank[RandomInteger[1,{10,10}]],{20}]

Estimate the average rank of a random 10×10 0–1 matrix:

Block[{n = 10000}, N[Sum[MatrixRank[RandomInteger[1,{10,10}]],{n}]/n]]

Find the ranks of coprimality arrays:

m=Table[If[CoprimeQ[x,y],1,0],{x,20},{y,20}];

MatrixRank[m]

ArrayPlot[m]

Table[MatrixRank[Table[If[CoprimeQ[x,y],1,0],{x,n},{y,n}]],{n,50}]

ListLinePlot[%]

OpenersExampleSection4(Spacer1)Properties & Relations  (4)

(RefLink[MatrixRank, paclet:ref/MatrixRank])[m] is equal to (RefLink[Length, paclet:ref/Length])[(RefLink[SingularValueList, paclet:ref/SingularValueList])[m]]:

m = N[RandomInteger[1, {4,4}]];

SingularValueList[m]

MatrixRank[m] == Length[%]

(RefLink[MatrixRank, paclet:ref/MatrixRank])[m] plus the dimension of the null space is equal to the number of columns of m:

m = N[RandomInteger[1, {4,4}]];

{r, c} = Dimensions[m];

ns = NullSpace[m]

c == Length[ns] + MatrixRank[m]

The column and row rank of a matrix are equal:

m={{1,2,3},{4,5,6},{7,8,9}};

{MatrixRank[m],MatrixRank[m\[Transpose]]}

The outer product of vectors has matrix rank 1:

v=RandomReal[1,1000];

MatrixRank[KroneckerProduct[v,v]]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

(RefLink[MatrixRank, paclet:ref/MatrixRank]) may depend on the precision of the given matrix:

m = {{1,2,3},{4,5,6},{7,8,9 + (10^(-20))}};

Use exact arithmetic to compute the matrix rank exactly:

MatrixRank[m]

Use machine arithmetic. Machine numbers cannot distinguish between 9 and 9+(10^(-20)):

MatrixRank[N[m]]

Use 24-digit-precision arithmetic:

MatrixRank[N[m, 24]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NullSpace, paclet:ref/NullSpace])  ▪  (RefLink[Det, paclet:ref/Det])  ▪  (RefLink[Eigensystem, paclet:ref/Eigensystem])  ▪  (RefLink[RowReduce, paclet:ref/RowReduce])  ▪  (RefLink[SingularValueList, paclet:ref/SingularValueList])  ▪  (RefLink[Inverse, paclet:ref/Inverse])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Solving Linear Systems, paclet:tutorial/SolvingLinearSystems])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Linear Systems, paclet:guide/LinearSystems])}, {▪(RefLinkPlain[Matrices and Linear Algebra, paclet:guide/MatricesAndLinearAlgebra])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(Spacer1)▪(RefLinkPlain[(Spacer1)Implementation notes: Numerical and Related Functions, paclet:tutorial/SomeNotesOnInternalImplementation#30506])}, {(Spacer1)▪(RefLinkPlain[(Spacer1)Implementation notes: Algebra and Calculus, paclet:tutorial/SomeNotesOnInternalImplementation#22549])}})}})