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

[ 3 4 5/2]<br />

sage: R. = QQ[]<br />

We rescale the last column <strong>of</strong> a matrix over a polynomial ring:<br />

sage: a = matrix(R,2,3,[1,x,x^2,x^3,x^4,x^5]); a<br />

[ 1 x x^2]<br />

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

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

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

[ x^3 x^4 1/2*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_col(2,1/2)<br />

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

...<br />

TypeError: Rescaling column by Rational Field element cannot be done over Integer Ring, use<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(2,1/2); a<br />

[0 1 1]<br />

[3 4 2]<br />

rescale_row(i, s, start_col=0)<br />

Replace i-th row <strong>of</strong> self by s times i-th row <strong>of</strong> self.<br />

INPUT:<br />

•i - ith row<br />

•s - scalar<br />

•start_col - only rescale entries at this column <strong>and</strong> to the right<br />

EXAMPLES: We rescale the second row <strong>of</strong> a matrix over the rational numbers:<br />

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

[0 1]<br />

[2 3]<br />

[4 5]<br />

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

[ 0 1]<br />

[ 1 3/2]<br />

[ 4 5]<br />

We rescale the second row <strong>of</strong> a matrix over a polynomial ring:<br />

sage: R. = QQ[]<br />

sage: a = matrix(R,3,[1,x,x^2,x^3,x^4,x^5]);a<br />

[ 1 x]<br />

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

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

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

[ 1 x]<br />

87

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

Saved successfully!

Ooh no, something went wrong!