# How to solve this equation with rank relation of matrix

It has been known that matrix A is equivalent to matrix B, and I want to find the possible value of parameter a (the answer is a = 2). This question is slightly different from that of this post.

A = {{1, 2, a}, {1, 3, 0}, {2, 7, -a}};
B = {{1, a, 2}, {0, 1, 1}, {-1, 1, 1}};
Solve[MatrixRank[A] == MatrixRank[B], a]


The above code can not output the correct results, I need your help.

Besides, I have another question. I find that RowReduce-function can't make the matrix with parameters into row simplest type:

RowReduce[{{1, a, 2}, {0, 1, 1}, {-1, 1, 1}}]


The row simplest form of matrix $$\left(\begin{array}{ccc} 1 & a & 2 \\ 0 & 1 & 1 \\ -1 & 1 & 1 \end{array}\right)$$ should be $$\left(\begin{array}{ccc} 1 & -1 & -1 \\ 0 & 1 & 1 \\ 0 & a-2 & 0 \end{array}\right)$$ instead of $$\left(\begin{array}{lll} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)$$. I wonder if this error is a bug in the RowReduce function.

In addition, sometimes it is necessary to deal with the following non square matrix equation:

A = {{1, -1, -1}, {2, a, 1}, {-1, 1, a}}; B = {{2, 2}, {1,
a}, {-a - 1, -2}};
Solve[MatrixRank[A] ==
MatrixRank[Join[A, B, 2]], a, Reals]

• To address the last question: This is not a bug in RowReduce (nor is it an error). Aug 5, 2020 at 14:50
• 1. There is no bug here. 2. You should know by now that the bugs tag is not to be applied unless other people have confirmed that what you've seen is a bug. Aug 5, 2020 at 14:51
• @DanielLichtblau If it's not a bug I would argue, though, that the documentation does a pretty bad job at explaining this limitation. Would it be feasible for RowReduce to have a GenerateConditions option to at least be able to keep track of the conditions that that make the reduced form valid? Aug 20, 2020 at 8:42
• @SjoerdSmit (1) I don't think such an option is likely to be added but in theory it is feasible. One way to obtain such information is to augment the matrix with an identity matrix on the right (as though finding a matrix inverse as taught in linear algebra), then row reduce, then take denominators in the augmented section as nonvanishing conditions. Aug 20, 2020 at 14:20
• @SjoerdSmit (2) See also this old response to a similar question, for adapting the ZeroTest option. Aug 20, 2020 at 14:22

It looks like RowReduce and MatrixRank implicitly assume that a does not have a particular value that reduces the rank of the matrix. They can detect that matrix A is degenerate for any value of a, but not that B is degenerate for a == 2.

I think you might be able to get around this with SingularValueList, which seems to handle the problem better:

Assuming[a \[Element] Reals,
Simplify[Reduce[Simplify[#] == 0] & /@ SingularValueList[A]]
]
Assuming[a \[Element] Reals,
Simplify[Reduce[Simplify[#] == 0] & /@ SingularValueList[B]]
]


{False, False}

{a == 2, False, False}

From this you can see that A always has rank 2 while B has rank 3 any value of a other than 2.

# Edit

Here's a quick attempt to do what you asked directly:

symbolicMatrixRank[mat_, assumptions_] := Assuming[assumptions,
Simplify @ Total @ Simplify[
Boole[!Reduce[Simplify[#] == 0]] & /@ SingularValueList[mat]
]
];
Solve[symbolicMatrixRank[A, a ∈ Reals] == symbolicMatrixRank[B, a ∈ Reals]]


{{a -> 2}}

or similarly:

symbolicMatrixRank[mat_, assumptions_] := Assuming[assumptions,
Simplify @ Total @ Map[
Boole @ Simplify @ Reduce[ConditionalExpression[#, \$Assumptions] != 0]&,
SingularValueList[mat]
]
];


As noted in a comment, Solve doesn't not always seem to deal with these sort of piecewise equations too well. Resolve is more adapt at solving them.

• Your answer is great, but how to deal with the following non square matrix equation:A = {{1, -1, -1}, {2, a, 1}, {-1, 1, a}}; B = {{2, 2}, {1, a}, {-a - 1, -2}}; Solve[symbolicMatrixRank[A, Element[a, Reals]] == symbolicMatrixRank[Join[A, B, 2], Element[a, Reals]]]. Aug 9, 2020 at 7:46
• @Montevideo For some reason Solve doesn't handle this very well. Try Reduce instead. It should give you 2 + a != 0. Aug 10, 2020 at 19:18
• @Montevideo Try the second form of symbolicMatrixRank I put in my answer. That one works here. Depending on the returned value of SingularValueList, you may need to wrangle a little with how you call Reduce and Simplify. I won't claim that these functions work for every imaginable matrix. Aug 16, 2020 at 19:26
• @Montevideo Please ask a new question. The comments aren't the right place for this. Aug 20, 2020 at 8:25
• @Montevideo I'm a bit busy atm, but I'll have a look when I have time. Aug 20, 2020 at 12:57

I have made a MatrixRankSym feature with symbolic computation here. And we can use it directly:

A = {{1, 2, a}, {1, 3, 0}, {2, 7, -a}};
B = {{1, a, 2}, {0, 1, 1}, {-1, 1, 1}};
Reduce[MatrixRankSym[A] == MatrixRankSym[B], a]


a == 2

For your second non square matrix equation:

A = {{1, -1, -1}, {2, a, 1}, {-1, 1, a}};
B = {{2, 2}, {1, a}, {-a - 1, -2}};
Reduce[MatrixRankSym[A] == MatrixRankSym[Join[A, B, 2]], a, Reals]


a < -2 || a > -2