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

[0 0]<br />

[0 0]<br />

An example over Q:<br />

sage: A = MatrixSpace(QQ,3)(range(9))<br />

sage: A.charpoly(’x’)<br />

x^3 - 12*x^2 - 18*x<br />

sage: A.trace()<br />

12<br />

sage: A.determinant()<br />

0<br />

We compute the characteristic polynomial <strong>of</strong> a matrix over the polynomial ring Z[a]:<br />

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

sage: M = MatrixSpace(R,2)([a,1, a,a+1]); M<br />

[ a 1]<br />

[ a a + 1]<br />

sage: f = M.charpoly(’x’); f<br />

x^2 + (-2*a - 1)*x + a^2<br />

sage: f.parent()<br />

Univariate Polynomial Ring in x over Univariate Polynomial Ring in a over Integer Ring<br />

sage: M.trace()<br />

2*a + 1<br />

sage: M.determinant()<br />

a^2<br />

We compute the characteristic polynomial <strong>of</strong> a matrix over the multi-variate polynomial ring Z[x, y]:<br />

sage: R. = PolynomialRing(ZZ,2)<br />

sage: A = MatrixSpace(R,2)([x, y, x^2, y^2])<br />

sage: f = A.charpoly(’x’); f<br />

x^2 + (-y^2 - x)*x - x^2*y + x*y^2<br />

It’s a little difficult to distinguish the variables. To fix this, we temporarily view the indeterminate as Z:<br />

sage: with localvars(f.parent(), ’Z’): print f<br />

Z^2 + (-y^2 - x)*Z - x^2*y + x*y^2<br />

We could also compute f in terms <strong>of</strong> Z from the start:<br />

sage: A.charpoly(’Z’)<br />

Z^2 + (-y^2 - x)*Z - x^2*y + x*y^2<br />

Here is an example over a number field:<br />

sage: x = QQ[’x’].gen()<br />

sage: K. = NumberField(x^2 - 2)<br />

sage: m = matrix(K, [[a-1, 2], [a, a+1]])<br />

sage: m.charpoly(’Z’)<br />

Z^2 - 2*a*Z - 2*a + 1<br />

sage: m.charpoly(’a’)(m) == 0<br />

True<br />

Here is an example over a general commutative ring, that is to say, as <strong>of</strong> version 4.0.2, SAGE does not<br />

even positively determine that S in the following example is an integral domain. But the computation <strong>of</strong><br />

the characteristic polynomial succeeds as follows:<br />

133

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

Saved successfully!

Ooh no, something went wrong!