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

sage: print decomp<br />

2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]]<br />

An exception is raised when the matrix is not bistochastic:<br />

sage: M = Matrix([[2,3],[2,2]])<br />

sage: decomp = sage.combinat.permutation.bistochastic_as_sum_<strong>of</strong>_permutations(M)<br />

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

...<br />

ValueError: The matrix is not bistochastic<br />

characteristic_polynomial(*args, **kwds)<br />

Synonym for self.charpoly(...).<br />

EXAMPLES:<br />

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

[1 2]<br />

[3 4]<br />

sage: a.characteristic_polynomial(’T’)<br />

T^2 - 5*T - 2<br />

charpoly(var=’x’, algorithm=None)<br />

Returns the characteristic polynomial <strong>of</strong> self, as a polynomial over the base ring.<br />

ALGORITHM:<br />

In the generic case <strong>of</strong> matrices over a ring (commutative <strong>and</strong> with unity), there is a division-free algorithm,<br />

which can be accessed using "df", with complexity O(n 4 ). Alternatively, by specifying<br />

"hessenberg", this method computes the Hessenberg form <strong>of</strong> the matrix <strong>and</strong> then reads <strong>of</strong>f the characteristic<br />

polynomial. Moreover, for matrices over number fields, this method can use PARI’s charpoly<br />

implementation instead.<br />

The method’s logic is as follows: If no algorithm is specified, first check if the base ring is a number<br />

field (<strong>and</strong> then use PARI), otherwise check if the base ring is the ring <strong>of</strong> integers modulo n (in which<br />

case compute the characteristic polynomial <strong>of</strong> a lift <strong>of</strong> the matrix to the integers, <strong>and</strong> then coerce back<br />

to the base), next check if the base ring is an exact field (<strong>and</strong> then use the Hessenberg form), or otherwise,<br />

use the generic division-free algorithm. If an algorithm is specified explicitly, if algorithm ==<br />

"hessenberg", use the Hessenberg form, or otherwise use the generic division-free algorithm.<br />

The result is cached.<br />

INPUT:<br />

•var - a variable name (default: ‘x’)<br />

•algorithm - string:<br />

EXAMPLES:<br />

– "df" - Generic O(n 4 ) division-free algorithm<br />

– "hessenberg" - Use the Hessenberg form <strong>of</strong> the matrix<br />

First a matrix over Z:<br />

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

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

sage: f<br />

x^2 - 5*x - 2<br />

sage: f.parent()<br />

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

sage: f(A)<br />

132 Chapter 7. Base class for matrices, part 2

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

Saved successfully!

Ooh no, something went wrong!