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

[1/2*x^2 1/2*x^3]<br />

[ x^4 x^5]<br />

We try <strong>and</strong> fail to rescale a matrix over the integers by a non-integer:<br />

sage: a = matrix(ZZ,2,3,[0,1,2, 3,4,4]); a<br />

[0 1 2]<br />

[3 4 4]<br />

sage: a.rescale_row(1,1/2)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: Rescaling row by Rational Field element cannot be done over Integer Ring, use cha<br />

To rescale the matrix by 1/2, you must change the base ring to the rationals:<br />

sage: a = a.change_ring(QQ); a<br />

[0 1 2]<br />

[3 4 4]<br />

sage: a.rescale_col(1,1/2); a<br />

[ 0 1/2 2]<br />

[ 3 2 4]<br />

set_col_to_multiple_<strong>of</strong>_col(i, j, s)<br />

Set column i equal to s times column j.<br />

EXAMPLES: We change the second column to -3 times the first column.<br />

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

[0 1 2]<br />

[3 4 5]<br />

sage: a.set_col_to_multiple_<strong>of</strong>_col(1,0,-3)<br />

sage: a<br />

[ 0 0 2]<br />

[ 3 -9 5]<br />

If we try to multiply a column by a rational number, we get an error message:<br />

sage: a.set_col_to_multiple_<strong>of</strong>_col(1,0,1/2)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: Multiplying column by Rational Field element cannot be done over Integer Ring, us<br />

set_immutable()<br />

Call this function to set the matrix as immutable.<br />

<strong>Matrices</strong> are always mutable by default, i.e., you can change their entries using A[i,j] = x. However,<br />

mutable matrices aren’t hashable, so can’t be used as keys in dictionaries, etc. Also, <strong>of</strong>ten when implementing<br />

a class, you might compute a matrix associated to it, e.g., the matrix <strong>of</strong> a Hecke operator. If you<br />

return this matrix to the user you’re really returning a reference <strong>and</strong> the user could then change an entry;<br />

this could be confusing. Thus you should set such a matrix immutable.<br />

EXAMPLES:<br />

sage: A = Matrix(QQ, 2, 2, range(4))<br />

sage: A.is_mutable()<br />

True<br />

sage: A[0,0] = 10<br />

sage: A<br />

[10 1]<br />

[ 2 3]<br />

88 Chapter 5. Base class for matrices, part 0

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

Saved successfully!

Ooh no, something went wrong!