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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<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 />

Also notice how matrices print. All columns have the same width <strong>and</strong> entries in a given column are right justified.<br />

Next we compute the reduced row echelon form <strong>of</strong> A.<br />

sage: A.rref()<br />

[ 1 0 -1933/3]<br />

[ 0 1 1550/3]<br />

3.1 Indexing<br />

<strong>Sage</strong> has quite flexible ways <strong>of</strong> extracting elements or submatrices from a matrix:<br />

sage: m=[(1, -2, -1, -1,9), (1, 8, 6, 2,2), (1, 1, -1, 1,4), (-1, 2, -2, -1,4)];M= matrix(m)<br />

sage: M<br />

[ 1 -2 -1 -1 9]<br />

[ 1 8 6 2 2]<br />

[ 1 1 -1 1 4]<br />

[-1 2 -2 -1 4]<br />

Get the 2 x 2 submatrix <strong>of</strong> M, starting at row index <strong>and</strong> column index 1:<br />

sage: M[1:3,1:3]<br />

[ 8 6]<br />

[ 1 -1]<br />

Get the 2 x 3 submatrix <strong>of</strong> M starting at row index <strong>and</strong> column index 1:<br />

sage: M[1:3,[1..3]]<br />

[ 8 6 2]<br />

[ 1 -1 1]<br />

Get the second column <strong>of</strong> M:<br />

sage: M[:,1]<br />

[-2]<br />

[ 8]<br />

[ 1]<br />

[ 2]<br />

Get the first row <strong>of</strong> M:<br />

sage: M[0,:]<br />

[ 1 -2 -1 -1 9]<br />

Get the last row <strong>of</strong> M (negative numbers count from the end):<br />

sage: M[-1,:]<br />

[-1 2 -2 -1 4]<br />

More examples:<br />

sage: M[range(2),:]<br />

[ 1 -2 -1 -1 9]<br />

[ 1 8 6 2 2]<br />

sage: M[range(2),4]<br />

[9]<br />

[2]<br />

sage: M[range(3),range(5)]<br />

[ 1 -2 -1 -1 9]<br />

[ 1 8 6 2 2]<br />

60 Chapter 3. <strong>Matrices</strong> over an arbitrary ring

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

Saved successfully!

Ooh no, something went wrong!