get the list of row operations to put a matrix into rref

49 views
Skip to first unread message

Dan Drake

unread,
Dec 30, 2014, 8:45:54 PM12/30/14
to sage...@googlegroups.com
Hi,

I'm teaching linear algebra and would like to automatically get a list
of the row operations one can use to put a matrix into reduced row
echelon form. So I coded up the usual algorithm:

https://gist.github.com/dandrake/6fa2f03b5dff632706a9

You can get a list of elementary matrices or a list of strings that
describe what one does:

sage: A
[ 1 2 0 -2 0]
[ 1 -2 1 -2 0]
[-1 0 0 -2 0]
sage: rref_steps(A)
['add $-1$ times row 1 to row 2',
'add $1$ times row 1 to row 3',
'scale row 2 by $-1/4$',
'add $-2$ times row 2 to row 1',
'add $-2$ times row 2 to row 3',
'scale row 3 by $2$',
'add $-1/2$ times row 3 to row 1',
'add $1/4$ times row 3 to row 2']
sage: prod(rref(A)) * A == A.rref()
True


Just sharing. Enjoy.

Dan

--
--- Dan Drake
----- www.math.wisc.edu/~ddrake/
-------
signature.asc

David Joyner

unread,
Dec 30, 2014, 8:49:11 PM12/30/14
to SAGE edu
On Tue, Dec 30, 2014 at 8:45 PM, Dan Drake <ddr...@math.wisc.edu> wrote:
> Hi,
>
> I'm teaching linear algebra and would like to automatically get a list
> of the row operations one can use to put a matrix into reduced row
> echelon form. So I coded up the usual algorithm:
>
> https://gist.github.com/dandrake/6fa2f03b5dff632706a9
>
> You can get a list of elementary matrices or a list of strings that
> describe what one does:
>
> sage: A
> [ 1 2 0 -2 0]
> [ 1 -2 1 -2 0]
> [-1 0 0 -2 0]
> sage: rref_steps(A)
> ['add $-1$ times row 1 to row 2',
> 'add $1$ times row 1 to row 3',
> 'scale row 2 by $-1/4$',
> 'add $-2$ times row 2 to row 1',
> 'add $-2$ times row 2 to row 3',
> 'scale row 3 by $2$',
> 'add $-1/2$ times row 3 to row 1',
> 'add $1/4$ times row 3 to row 2']
> sage: prod(rref(A)) * A == A.rref()
> True
>

Very useful, thanks!

>
> Just sharing. Enjoy.
>
> Dan
>
> --
> --- Dan Drake
> ----- www.math.wisc.edu/~ddrake/
> -------
>
> --
> You received this message because you are subscribed to the Google Groups "sage-edu" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-edu+u...@googlegroups.com.
> To post to this group, send email to sage...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-edu.
> For more options, visit https://groups.google.com/d/optout.

Norbert Domes

unread,
Jan 16, 2015, 5:36:13 AM1/16/15
to sage...@googlegroups.com
Further you may have a look at

http://ask.sagemath.org/question/8840/how-to-show-the-steps-of-gauss-method/

and at my adaptation as interactive worksheet

http://85.214.246.147:8080/home/pub/203/

Norbert
Reply all
Reply to author
Forward
0 new messages