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: M1=Matrix(QQ,[[-1,0],[-1/2,-1]])<br />

sage: M2=Matrix(ZZ,[[1,-1,2],[-2,4,8]])<br />

sage: M1.tensor_product(M2)<br />

[ -1 1 -2| 0 0 0]<br />

[ 2 -4 -8| 0 0 0]<br />

[--------------+--------------]<br />

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

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

sage: M2.tensor_product(M1)<br />

[ -1 0| 1 0| -2 0]<br />

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

[---------+---------+---------]<br />

[ 2 0| -4 0| -8 0]<br />

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

Subdivisions can be optionally suppressed.<br />

sage: M1.tensor_product(M2, subdivide=False)<br />

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

[ 2 -4 -8 0 0 0]<br />

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

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

Different base rings are h<strong>and</strong>led sensibly.<br />

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

sage: B = matrix(FiniteField(23), 3, 4, range(12))<br />

sage: C = matrix(FiniteField(29), 4, 5, range(20))<br />

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

sage: D.parent()<br />

Full MatrixSpace <strong>of</strong> 6 by 12 dense matrices over Finite Field <strong>of</strong> size 23<br />

sage: E = C.tensor_product(B)<br />

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

...<br />

TypeError: unsupported oper<strong>and</strong> parent(s) for ’*’: ’Finite Field <strong>of</strong> size 29’ <strong>and</strong> ’Full Matrix<br />

The input is checked to be sure it is a matrix.<br />

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

sage: A.tensor_product(’junk’)<br />

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

...<br />

TypeError: tensor product requires a second matrix, not junk<br />

trace()<br />

Return the trace <strong>of</strong> self, which is the sum <strong>of</strong> the diagonal entries <strong>of</strong> self.<br />

INPUT:<br />

•self - a square matrix<br />

OUTPUT: element <strong>of</strong> the base ring <strong>of</strong> self<br />

EXAMPLES:<br />

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

[0 1 2]<br />

[3 4 5]<br />

[6 7 8]<br />

sage: a.trace()<br />

12<br />

261

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

Saved successfully!

Ooh no, something went wrong!