1

I'm trying to row reduce a matrix with variables in the last column:

s, t = symbols('s t')
S = Matrix(2,3, [2,-1, s, 1, -1/2, t])

So, Matrix([[2, -1, s], [1, -0.500000000000000, t]]). When row reduced, the second row should be 0 0 t - s/2, that is, an expression in s and t (so the matrix is singular unless s = 2t). But SymPy returns:

Matrix([[1, -1/2, 0], [0, 0, 1]])

This question gets at this same issue but the solution there (passing simplify = True into the rref method) doesn't work for me, and I have tried several of the other possible simplify options with no luck. For example, passing simplify = cancel gives me the same result and passing just cancel as the first argument gives me the matrix Matrix([[2, 0, s], [1, 0, t]]).

What simplifying option should be passed, and how should I invoke it?

1 Answers1

0

The reduced row echelon form (RREF) by definition has the leading entry of each row normalised to 1:

https://en.wikipedia.org/wiki/Row_echelon_form

In [5]: S
Out[5]: 
⎡2   -1   s⎤
⎢          ⎥
⎣1  -0.5  t⎦

In [6]: S.rref()[0]
Out[6]: 
⎡1  -1/2  0⎤
⎢          ⎥
⎣0   0    1⎦

What you are looking for is the (unreduced) row echelon form which SymPy provides as echelon_form:

In [7]: S.echelon_form()
Out[7]: 
⎡2  -1     s    ⎤
⎢               ⎥
⎣0  0   -s + 2⋅t⎦

If you ask for the RREF then SymPy will divide each row by its leading entry and also subtract from all columns above that leading entry. This is not necessarily valid for all possible values of symbolic parameters e.g. it might be that s = 2*t but for generic values of the parameters this is the correct RREF.

so the matrix is singular unless s = 2t

It doesn't make sense to talk about rectangular matrices being singular. If the matrix we have here is considered to be the augmented matrix for a system of equations then that system of equations has no solutions unless s = 2*t. In that context the unaugmented matrix (i.e. the first two columns of S) is singular regardless of the values of s and t.

Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14