# Row echelon form of a matrix containing symbolic expresssions

Hi,

I want to find out the row echelon form of this matrix:

$\left(\begin{array}{rrrr} 1 & 1 & 2 & b_{1} \\ 1 & 0 & 1 & b_{2} \\ 2 & 1 & 3 & b_{3} \end{array}\right)$

By manually performing elementary row operations on paper, I get this answer:

$\left(\begin{array}{rrrr} 1 & 1 & 2 & b_{1} \\ 0 & 1 & 1 & b_{1} - b_{2} \\ 0 & 0 & 0 & -b_{1} - b_{2} + b_{3} \end{array}\right)$

I thought I can do the following in sage:

var('b_1,b_2,b_3')
A=matrix(SR,[[1,1,2,b_1],[1,0,1,b_2],[2,1,3,b_3]])
show(A)
A.echelon_form()

But I get:

$\left(\begin{array}{rrrr} 1 & 0 & 1 & 0 \\ 0 & 1 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array}\right)$

What is the correct function and/or parameters I should use to get the expected answer?

Thank you.

edit retag close merge delete

Sort by » oldest newest most voted

This is typical---it is assumed that you can divide and things aren't zero. This happens in other math software systems too. The Maple chapter of the Handbook of Linear Algebra discusses this (p. 72-10) and refers to these two references:

• R.M. Corless and D.J. Jeffrey. Well... it isnt quite that simple. SIGSAM Bull., 26(3):26, 1992.
• R.M. Corless and D.J. Jeffrey. The Turing factorization of a rectangular matrix. SIGSAM Bull., 31(3):2028, 1997.

That HLA chapter suggests using LU decomposition to do this, but apparently LU decomposition doesn't work too well for our symbolic matrix.

HOWEVER: You can do this in Sage if you use a different base ring for the matrices:

sage: R.<b1,b2,b3>=QQ[]
sage: A=matrix([[1,1,2,b1],[1,0,1,b2],[2,1,3,b3]])
sage: A.echelon_form()
[            1             0             1            b2]
[            0             1             1       b1 - b2]
[            0             0             0 -b1 - b2 + b3]

Note that rref still gives the answer you got before since rref works over the fraction field:

sage: A.rref()
[1 0 1 0]
[0 1 1 0]
[0 0 0 1]
sage: parent(A)
Full MatrixSpace of 3 by 4 dense matrices over Multivariate Polynomial Ring in b1, b2, b3 over Rational Field
sage: parent(A.echelon_form())
Full MatrixSpace of 3 by 4 dense matrices over Multivariate Polynomial Ring in b1, b2, b3 over Rational Field
sage: parent(A.rref())
Full MatrixSpace of 3 by 4 dense matrices over Fraction Field of Multivariate Polynomial Ring in b1, b2, b3 over Rational Field
more
sage: P.<b1,b2,b3> = QQ[]
sage: A = Matrix(P, 3, 4, [[1,1,2,b1], [1,0,1,b2], [2,1,3,b3]])
sage: A
[ 1  1  2 b1]
[ 1  0  1 b2]
[ 2  1  3 b3]
sage: A.echelon_form('row_reduction')
[            1             0             1            b2]
[            0             1             1       b1 - b2]
[            0             0             0 -b1 - b2 + b3]
more

The definition of the echelon form of a matrix requires (amongst others) that the first non-zero element on each row be a 1. So, from your results the next step is to multiply the last row by 1/(-b1-b2+b3) which leads to

[[1,1,2,   b1]
[0,1,1,b1-b2]
[0,0,0,   1]]

and then, you can subtract the last row times (b1-b2) and times b1 from the 2nd and the 1st row, leading to

[[1,1,2,0]
[0,1,1,0]
[0,0,0,1]]

finally you can subtract the 2nd from the 1st row leading to

[[1,0,1,0]
[0,1,1,0]
[0,0,0,1]]

So, everything is ok.

B.t.w.: the reason why you can completely wipe out your 'variables' b1...b3 is because the cols/rows of the rest of the matrix are linearly dependent. You will experience the same thing for any other case where this holds because one of the rows of your matrix will contain only zeros up to the row which contains the variables.

more

@Jason Grout: 1) "..it is assumed that you can divide and things aren't zero...". Yes. Exactly that is what happens.

2) "..This happens in other math software systems too..". Yes again, eg. also in Mathematica:

In[4]:= RowReduce[{{1, 1, 2, b1}, {1, 0, 1, b2}, {2, 1, 3, b3}}]
Out[4]= {{1, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 1}}
more