08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

sage: A.swap_columns(1,2); A<br />

[ 1 -7 9]<br />

[4/5 3 4]<br />

[ 6 3 4]<br />

swap_rows(r1, r2)<br />

Swap rows r1 <strong>and</strong> r2 <strong>of</strong> self.<br />

EXAMPLES: We create a rational matrix:<br />

sage: M = MatrixSpace(QQ,3,3)<br />

sage: A = M([1,9,-7,4/5,4,3,6,4,3])<br />

sage: A<br />

[ 1 9 -7]<br />

[4/5 4 3]<br />

[ 6 4 3]<br />

Since the first row is numbered zero, this swaps the first <strong>and</strong> third rows:<br />

sage: A.swap_rows(0,2); A<br />

[ 6 4 3]<br />

[4/5 4 3]<br />

[ 1 9 -7]<br />

with_added_multiple_<strong>of</strong>_column(i, j, s, start_row=0)<br />

Add s times column j to column i, returning new matrix.<br />

EXAMPLES: We add -1 times the third column to the second column <strong>of</strong> an integer matrix, remembering<br />

to start numbering cols at zero:<br />

sage: a = matrix(ZZ,2,3,range(6)); a<br />

[0 1 2]<br />

[3 4 5]<br />

sage: b = a.with_added_multiple_<strong>of</strong>_column(1,2,-1); b<br />

[ 0 -1 2]<br />

[ 3 -1 5]<br />

The original matrix is unchanged:<br />

sage: a<br />

[0 1 2]<br />

[3 4 5]<br />

Adding a rational multiple is okay, <strong>and</strong> reassigning a variable is okay:<br />

sage: a = a.with_added_multiple_<strong>of</strong>_column(0,1,1/3); a<br />

[ 1/3 1 2]<br />

[13/3 4 5]<br />

with_added_multiple_<strong>of</strong>_row(i, j, s, start_col=0)<br />

Add s times row j to row i, returning new matrix.<br />

EXAMPLES: We add -3 times the first row to the second row <strong>of</strong> an integer matrix, remembering to start<br />

numbering rows at zero:<br />

sage: a = matrix(ZZ,2,3,range(6)); a<br />

[0 1 2]<br />

[3 4 5]<br />

sage: b = a.with_added_multiple_<strong>of</strong>_row(1,0,-3); b<br />

[ 0 1 2]<br />

[ 3 1 -1]<br />

91

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!