2
$\begingroup$

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$?

$\endgroup$
5
  • 2
    $\begingroup$ It's not "very different" in the sense that if you do divide by 479, then a round of operations involving the two last columns gives you what you wanted. I don't know why Sages doesn't do it. May be it is doing arithmetic over an unknown ring and is not certain whether $479=0$ or not? May be it is working over integers only? $\endgroup$ Aug 10 '14 at 12:34
  • 1
    $\begingroup$ The form shown "from the book" is called reduced row-echelon form, wherein leading ones have columns that are otherwise zeros. The row-echelon form only requires entries below leading ones to be zeros. $\endgroup$
    – hardmath
    Aug 10 '14 at 12:38
  • $\begingroup$ @JyrkiLahtonen: you were right on the integers. I changed the type to rationals (QQ) and now it computed the reduced row echelon form. $\endgroup$
    – fstab
    Aug 10 '14 at 12:46
  • 1
    $\begingroup$ Glad to hear that you solved the problem! $\endgroup$ Aug 10 '14 at 13:04
  • 2
    $\begingroup$ @francescostablum: Now that you've done the research, this would be a good solution for you to write up as a self-Answer! (Your "update" would do fine IMHO.) $\endgroup$
    – hardmath
    Aug 10 '14 at 15:07
3
$\begingroup$

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]
$\endgroup$
1
$\begingroup$

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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.