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.

CHAPTER<br />

THIRTEEN<br />

SPARSE MATRICES OVER A GENERAL<br />

RING<br />

Sparse <strong>Matrices</strong> over a general ring<br />

EXAMPLES:<br />

sage: R. = PolynomialRing(QQ)<br />

sage: M = MatrixSpace(QQ[’x’],2,3,sparse=True); M<br />

Full MatrixSpace <strong>of</strong> 2 by 3 sparse matrices over Univariate Polynomial Ring in x over Rational Field<br />

sage: a = M(range(6)); a<br />

[0 1 2]<br />

[3 4 5]<br />

sage: b = M([x^n for n in range(6)]); b<br />

[ 1 x x^2]<br />

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

sage: a * b.transpose()<br />

[ 2*x^2 + x 2*x^5 + x^4]<br />

[ 5*x^2 + 4*x + 3 5*x^5 + 4*x^4 + 3*x^3]<br />

sage: pari(a)*pari(b.transpose())<br />

[2*x^2 + x, 2*x^5 + x^4; 5*x^2 + 4*x + 3, 5*x^5 + 4*x^4 + 3*x^3]<br />

sage: c = copy(b); c<br />

[ 1 x x^2]<br />

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

sage: c[0,0] = 5; c<br />

[ 5 x x^2]<br />

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

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

1<br />

sage: c.dict()<br />

{(0, 1): x, (1, 2): x^5, (0, 0): 5, (1, 0): x^3, (0, 2): x^2, (1, 1): x^4}<br />

sage: c.list()<br />

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

sage: c.rows()<br />

[(5, x, x^2), (x^3, x^4, x^5)]<br />

sage: TestSuite(c).run()<br />

sage: d = c.change_ring(CC[’x’]); d<br />

[5.00000000000000 x x^2]<br />

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

sage: latex(c)<br />

\left(\begin{array}{rrr}<br />

5 & x & x^{2} \\<br />

x^{3} & x^{4} & x^{5}<br />

\end{array}\right)<br />

291

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

Saved successfully!

Ooh no, something went wrong!