The current MatrixRank is a slight foolish without any capacity of symbolic computation ,feature of Mathematica, like this:
(mat = Normal@SparseArray[{i_, i_} -> a, 5, b]) // MatrixForm
MatrixRank[mat]
(*5*)
But actually we expect the result in mathematics is:
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
I'd like to be Solve's result:
In[1]:= Solve[x^2 + y^2 + x == 1, y, Reals]
Out[1]= {{y ->
ConditionalExpression[-Sqrt[1 - x - x^2],
1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]}, {y ->
ConditionalExpression[Sqrt[1 - x - x^2],
1/2 (-1 - Sqrt[5]) < x < 1/2 (-1 + Sqrt[5])]}}
It will give a ConditionalExpression for every result.And I think the Mathematica can do it via some solution.like following we can find some condition for this:
But I don't know what I should to do next for this.So help Mathematica,help me to improve or rewrite the MatrixRank,give some thinking,please.




Out[10]= {a - b, a - b, a - b, a - b, a + 4 b}
– Daniel Lichtblau Oct 15 '15 at 14:30. Next take all subsets and invoke something likeSolve[subset==0&&Complement[set,subset]!=0]` to find all cases where rank= #subset. In this case of course it simplifies since there is a repeated root, but this should give the general idea.LUDecomposition[], and then do the checks described by Daniel on the diagonal entries of the upper triangular factor. – J. M.'s missing motivation Oct 15 '15 at 15:15