yode
yode

Reputation: 643

How to calculate the rank with Symbolic

Code:

with(LinearAlgebra): 
mat := Matrix([[a, b, b, b, b], [b, a, b, b, b], [b, b, a, b, b],
 [b, b, b, a, b], [b, b, b, b, a]]);
Rank(mat);

Function Rank just gave me a result of 5, but actually:

when a=b=0,rank(mat)=0
when a=b≠0,rank(mat)=1
when a+4b=0,rank(mat)=4
when a≠b&&a≠-4b,rank(mat)=5

The maple calculated it as a different condition?

Upvotes: 1

Views: 195

Answers (1)

John M
John M

Reputation: 295

In most cases Maple treats symbols such as a and b in this example as being generic (e.g. they don't satisfy any algebraic equations such as a-b=0 etc) and under those assumptions, the rank is 5. This is not a totally useless result, since it is possible to have a symbolic matrix that is not generically full rank.

If you want to get all the cases, I think you probably have to proceed manually calculating the symbolic determinants/minors and finding their roots. e.g.

d5 := LinearAlgebra:-Determinant(mat);
s := {solve(d5, a)}; # two solutions
mat1 := eval(mat, a = s[1]); # a=b
LinearAlgebra:-Rank(mat1); # rank=1
mat2 := eval(mat, a = s[2]); # a=-4*b
LinearAlgebra:-Rank(mat2); # rank=3

To drill down to lower rank case, you'll need to start looking at zeros of the minors of mat1 and mat2. Since mat1 is rank 1, you have to look at what makes its 1x1 minors zero, but since mat1 has all identical entries, that condition is just b=0.

You still have to check mat2 because there might be a rank=2 case, or other conditions on b that give you rank 1 or 0.

minors := { seq(seq(LinearAlgebra:-Minor(mat2, i, j), i=1..5), j=1..5)) };
s2 := solve(minors, b); # {b=0}
LinearAlgebra:-Rank( eval(mat2, s2) ); # 0

This shows us that the only lower rank possibility when a=-4*b is when b=0, so the same rank 0 condition as when a=b. So that's all the cases.

If that hadn't been all the cases, then you would have to look at 3x3 and 2x2 minors which would require judicious use of the LinearAlgebra:-SubMatrix command. In the general case, this approach could lead to a lot of case splitting and there is almost certainly a better way to do it more generally that reuses the minor calculations.

If you have reason to believe that your matrix is generically diagonalizable then you could look at where the coefficients of the characteristic polynomial vanish.

Upvotes: 2

Related Questions