# RowReduce for symbolic matrices

I'd like to invoke RowReduce on some matrices with a time parameter.

For example consider

A = {{1, 0}, {0, t}}


If t = 0, we have

RowReduce[A /. t -> 0] = {{1, 0}, {0, 0}}


but RowReduce[A] always returns the identity matrix.

How can I tell Mathematica to distinguish cases where there might be division by zero?

Edit: Maybe I need to clarify my problem a bit more. I don't know much about the matrices, except that they contain some time dependence. Now, whatever form the given matrix has, I want to perform some operation to attain a (time-depending) row-echelon form of my matrix that is valid for all $t \in I\subseteq\mathbb{R}$.

• Cannot do this directly using RowReduce. But Reduce, as below, can give similar information. Reduce[A.{x, y} == {z, w}] Out= x == z && ((y != 0 && t == w/y) || (y == 0 && w == 0)) – Daniel Lichtblau Jul 29 '13 at 13:52
• To take up your point. I think this might solve the problem, but implementation would be really ugly, because I don't want to solve a linear system. – user8774 Jul 30 '13 at 14:33

This problem is discussed in the "Handbook of Linear Algebra" book:

When standard linear algebra methods are applied to matrices containing symbolic entries, the user must be aware of new mathematical features that can arise. The main feature is the discontinuity of standard matrix functions, such as the reduced row-echelon form and the rank, both of which can be discontinuous. [...] The recommended solution is to use Turing factoring (generalized PLU decomposition) to obtain the reduced row-echelon form with provisos.

I don't think that the "Turing factorization of rectangular matrix" is implemented in Mathematica (it seems to be the case for Maple and Matlab). You can always settle on a upper-triangular form from the plain LU decomposition, which does not make assumptions such as those made by the RowReduce function:

m = {{aa, bb}, {cc, dd}};
n = Length[m] (* == Length[Transpose[m]]*)
{lu, p, c} = LUDecomposition[m];
(u = lu  SparseArray[{i_, j_} /; j >= i -> 1, {n, n}]) // TableForm

(* sanity check *)
l = lu SparseArray[{i_, j_} /; j < i -> 1, {n, n}] + IdentityMatrix[n];
m[[p]] == l.u


• hmm, I did see the question, but I don't see the point. Again, aa is assumed to be not zero, or not? – user8774 Jul 29 '13 at 16:09
• LUDecomposition is indeed making the tacit assumption that aa is invertible. – Daniel Lichtblau Jul 29 '13 at 20:09
• True, in this example LUDecomposition assumes existence of the element which is an inverse of aa. The difference with respect to RowReduce is that you get to still do symbolic computations and correctly evaluate reduced matrix at different points, including those for which it may pose problems. E.g. u /. {aa -> 0} gives a fair answer here. – trybik Jul 30 '13 at 13:10
• "Correctly" is an overstatement -LUDecomposition[m /. {aa -> 0}]] is well defined. – trybik Jul 30 '13 at 13:24

I believe this is a case where Mathematica is giving a generic answer: for all t!=0, the proper answer is indeed the 2 by 2 identity, but for the specific value t=0, you get the specific solution. So one way to distinguish these is to do a test of the matrix rank and then proceed accordingly. For the test case,

a = {{1, 0}, {0, t}};
MatrixRank[a]


gives 2 but

MatrixRank[a /. t -> 0]


gives 1. More generally, say the matrix has a function of t:

a = {{1, 0}, {0, f[t]}};


Then one can similarly test using

MatrixRank[a]
MatrixRank[a /. f[t] -> 0]


The first returns 2 and the second gives 1.

• Well, but how to do this test if expression gets more complex? For example if we have instead of t t^2 -2? – user8774 Jul 29 '13 at 14:56
• Okay, now this works for this special case. But if we replace the zeros by ones, we would have to test whether t=1. – user8774 Jul 29 '13 at 15:19
• I think you need to clarify what problem you want solved: the above answers the two questions you asked. – bill s Jul 29 '13 at 15:28

If you "don't know much about matrices" the Presentations Application, which I sell through my web site, has a Student's Linear Equation section that allows one to manipulate matrix structures step by step using various basic matrix operations. One can compose matrix structures, operate on them, print them and there is also a palette display from which one can paste positions. One can also display the matrices in equation form. Linear programming operations are allowed as well as the regular operations. There is even a provision for contravariant columns. One of the problems with matrices is that they lack context. How was the original matrix defined? Are you dealing with it, or the transpose, or the inverse, or the inverse transpose? Here the rows and columns are always labeled to give context. So here is a variant of your example:

<< Presentations
amat = {{1, t}, {-1, 0}};


First we set up the matrix form. The LEWhiteboard is a palette that displays the current structure and allows positions to be pasted into commands.

seExample = LECreate[2, 4];
LEColumnDividers[seExample, {2}]
LEWhiteboard[seExample]
LEPrint[seExample] Next we fill in the matrix also giving new row and column names.

LEInsertRowNames[seExample, 1, {y1, y2}]
LEInsertColumnNames[seExample, 1, {x1, x2, y1, y2}]
LEInsertMatrix[seExample, {1, 1}, amat]
LEInsertMatrix[seExample, {1, 3}, IdentityMatrix]
LEPrint[seExample] The following extracts the equations from the matrix structure.

LERowExpression[seExample, #, 3 ;; 4] ==
LERowExpression[seExample, #, 1 ;; 2] & /@ {1, 2} // Column The following does a pivot on the first row and column to give upper echelon row form. One can do full pivots or just pivot on select rows.

LEPivot[seExample, {1, 1}, 2 ;; 2]
LEPrint[seExample] Next we set t to zero and also draw an extra row divider.

seExample = seExample /. t -> 0;
LERowDividers[seExample, {1}]
LEPrint[seExample] Finally, we display the new row equations. The last equation gives the restraint that must hold among the y's when t = 0.

LERowExpression[seExample, #, 3 ;; 4] ==
LERowExpression[seExample, #, 1 ;; 2] & /@ {1, 2} // Column
` This is useful for learning basic matrix operations and working small problems within a context.

• The OP actually said "I don't know much about the matrices" - I think they were implying that there is a lack of a priori information about the specific matrices to be processed. – Simon Woods Jul 29 '13 at 20:12
• @SimonWoods is right, I'm sorry for the misleading formulation. – user8774 Jul 30 '13 at 14:35