Main Content

rank

Find rank of symbolic matrix

Syntax

Description

example

rank(A) returns the rank of symbolic matrix A.

Examples

Find Rank of Matrix

syms a b c d
A = [a b; c d];
rank(A)
ans =
     2

Rank of Symbolic Matrices Is Exact

Symbolic calculations return the exact rank of a matrix while numeric calculations can suffer from round-off errors. This exact calculation is useful for ill-conditioned matrices, such as the Hilbert matrix. The rank of a Hilbert matrix of order n is n.

Find the rank of the Hilbert matrix of order 15 numerically. Then convert the numeric matrix to a symbolic matrix using sym and find the rank symbolically.

H = hilb(15);
rank(H)
rank(sym(H))
ans =
    12
ans =
    15

The symbolic calculation returns the correct rank of 15. The numeric calculation returns an incorrect rank of 12 due to round-off errors.

Rank Function Does Not Simplify Symbolic Calculations

Consider this matrix

A=[1sin2(x)cos2(x)11].

After simplification of 1-sin(x)^2 to cos(x)^2, the matrix has a rank of 1. However, rank returns an incorrect rank of 2 because it does not take into account identities satisfied by special functions occurring in the matrix elements. Demonstrate the incorrect result.

syms x
A = [1-sin(x) cos(x); cos(x) 1+sin(x)];
rank(A)
ans =
     2

rank returns an incorrect result because the outputs of intermediate steps are not simplified. While there is no fail-safe workaround, you can simplify symbolic expressions by using numeric substitution and evaluating the substitution using vpa.

Find the correct rank by substituting x with a number and evaluating the result using vpa.

rank(vpa(subs(A,x,1)))
ans =
     1

However, even after numeric substitution, rank can return incorrect results due to round-off errors.

Input Arguments

collapse all

Input, specified as a number, vector, or matrix or a symbolic number, vector, or matrix.

Version History

Introduced before R2006a

See Also

| |