Row echelon form of (augmented) matrix. Is there something wrong with Sage's implementation?

1k Views Asked by At

I am trying to solve the exercise RREF.C10 from the A first course in Linear Algebra free book.

The exercise aims at finding the reduced row echelon form of the following linear system:

$\begin{align*} 2x_1-3x_2+x_3+7x_4&=14\\ 2x_1+8x_2-4x_3+5x_4&=-1\\ x_1+3x_2-3x_3&=4 \\ -5x_1+2x_2+3x_3+4x_4&=-19 \end{align*}$

After attempting a solution on paper, I looked for the solution with Sage:

C10A = matrix([[2,-3,1,7],[2,8,-4,5],[1,3,-3,0],[-5,2,3,4]])
C10b = vector([14,-1,4,-19])
C10M = C10A.augment(C10b, subdivide=True)
C10M
C10A.echelon_form()
C10M.echelon_form()

with the following outcome:

[  2  -3   1   7| 14]
[  2   8  -4   5| -1]
[  1   3  -3   0|  4]
[ -5   2   3   4|-19]

[  1   0   0 273]
[  0   1   0 315]
[  0   0   1 406]
[  0   0   0 479]

[  1   0   0 273 274]
[  0   1   0 315 312]
[  0   0   1 406 402]
[  0   0   0 479 479]

Unfortunately the reported solution from the book is very different:

\begin{equation*} \begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & -3\\ 0 & 0 & 1 & 0 & -4\\ 0 & 0 & 0 & 1 & 1 \end{bmatrix} \end{equation*}

I wonder what causes this discrepancy. Is Sage's implementation broken? Or is it just the solution from the book that is broken?

Moreover, why isn't Sage multiplying the last row for $\frac{1}{479}$ in order to have a leading $1$?

2

There are 2 best solutions below

0
On

Setting explicitly the type of the numbers to rationals (QQ), actually solved the problem, giving the unique reduced row echelon form, instead of just one row echelon form:

C10A = matrix(QQ,[[2,-3,1,7],[2,8,-4,5],[1,3,-3,0],[-5,2,3,4]])
C10b = vector(QQ,[14,-1,4,-19])
C10M = C10A.augment(C10b, subdivide=True)
C10M
C10A.echelon_form()
C10M.echelon_form()


[  2  -3   1   7| 14]
[  2   8  -4   5| -1]
[  1   3  -3   0|  4]
[ -5   2   3   4|-19]

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

[ 1  0  0  0| 1]
[ 0  1  0  0|-3]
[ 0  0  1  0|-4]
[ 0  0  0  1| 1]
0
On

Good sleuthing! In order to relieve those who don't know about rings from needing to learn about them while preserving easy access to this functionality, Sage also has the rref() method for such matrices (reduced row echelon form):

sage: C10A.echelon_form()
[  1   0   0 273]
[  0   1   0 315]
[  0   0   1 406]
[  0   0   0 479]
sage: C10A.rref()
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]

In fact, if you look at the section marked "Sage RREF Reduced Row-Echelon Form", you will see that Rob says the following:

You may notice that Sage has some commands with the word “echelon” in them. For now, these should be avoided like the plague, as there are some subtleties in how they work.

Indeed, though you figured it out. Good luck!