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.add_multiple_<strong>of</strong>_row(1,0,-3)<br />

sage: a<br />

[ 0 1 2]<br />

[ 3 1 -1]<br />

To add a rational multiple, we first need to change the base ring:<br />

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

sage: a.add_multiple_<strong>of</strong>_row(1,0,1/3)<br />

sage: a<br />

[ 0 1 2]<br />

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

If not, we get an error message:<br />

sage: a.add_multiple_<strong>of</strong>_row(1,0,i)<br />

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

...<br />

TypeError: Multiplying row by Symbolic Ring element cannot be done over Rational Field, use<br />

anticommutator(other)<br />

Return the anticommutator self <strong>and</strong> other.<br />

The anticommutator <strong>of</strong> two n × n matrices A <strong>and</strong> B is defined as {A, B} := AB + BA (sometimes this<br />

is written as [A, B] + ).<br />

EXAMPLES:<br />

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

sage: B = Matrix(ZZ, 2, 2, [0, 1, 0, 0])<br />

sage: A.anticommutator(B)<br />

[2 3]<br />

[0 2]<br />

sage: A.anticommutator(B) == B.anticommutator(A)<br />

True<br />

sage: A.commutator(B) + B.anticommutator(A) == 2*A*B<br />

True<br />

base_ring()<br />

Returns the base ring <strong>of</strong> the matrix.<br />

EXAMPLES:<br />

sage: m=matrix(QQ,2,[1,2,3,4])<br />

sage: m.base_ring()<br />

Rational Field<br />

change_ring(ring)<br />

Return the matrix obtained by coercing the entries <strong>of</strong> this matrix into the given ring.<br />

Always returns a copy (unless self is immutable, in which case returns self).<br />

EXAMPLES:<br />

sage: A = Matrix(QQ, 2, 2, [1/2, 1/3, 1/3, 1/4])<br />

sage: A.parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 dense matrices over Rational Field<br />

sage: A.change_ring(GF(25,’a’))<br />

[3 2]<br />

[2 4]<br />

sage: A.change_ring(GF(25,’a’)).parent()<br />

71

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

Saved successfully!

Ooh no, something went wrong!