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

And a few unproductive, but illustrative, examples.<br />

sage: A = matrix(ZZ, 3, 4, range(12))<br />

sage: B = column_matrix(ZZ, 3, 4, range(12))<br />

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

True<br />

sage: A = matrix(QQ, 7, 12, range(84))<br />

sage: A == column_matrix(A.columns())<br />

True<br />

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

sage: A<br />

[0 2 4]<br />

[1 3 5]<br />

sage: A.parent()<br />

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

sage.matrix.constructor.companion_matrix(poly, format=’right’)<br />

This function is available as companion_matrix(...) <strong>and</strong> matrix.companion(...).<br />

Create a companion matrix from a monic polynomial.<br />

INPUT:<br />

•poly - a univariate polynomial, or an iterable containing the coefficients <strong>of</strong> a polynomial, with low-degree<br />

coefficients first. The polynomial (or the polynomial implied by the coefficients) must be monic. In other<br />

words, the leading coefficient must be one. A symbolic expression that might also be a polynomial is not<br />

proper input, see examples below.<br />

•format - default: ‘right’ - specifies one <strong>of</strong> four variations <strong>of</strong> a companion matrix. Allowable values are<br />

‘right’, ‘left’, ‘top’ <strong>and</strong> ‘bottom’, which indicates which border <strong>of</strong> the matrix contains the negatives <strong>of</strong> the<br />

coefficients.<br />

OUTPUT:<br />

A square matrix with a size equal to the degree <strong>of</strong> the polynomial. The returned matrix has ones above, or below<br />

the diagonal, <strong>and</strong> the negatives <strong>of</strong> the coefficients along the indicated border <strong>of</strong> the matrix (excepting the leading<br />

one coefficient). See the first examples below for precise illustrations.<br />

EXAMPLES:<br />

Each <strong>of</strong> the four possibilities. Notice that the coefficients are specified <strong>and</strong> their negatives become the entries<br />

<strong>of</strong> the matrix. The leading one must be given, but is not used. The permutation matrix P is the identity matrix,<br />

with the columns reversed. The last three statements test the general relationships between the four variants.<br />

sage: poly = [-2, -3, -4, -5, -6, 1]<br />

sage: R = companion_matrix(poly, format=’right’); R<br />

[0 0 0 0 2]<br />

[1 0 0 0 3]<br />

[0 1 0 0 4]<br />

[0 0 1 0 5]<br />

[0 0 0 1 6]<br />

sage: L = companion_matrix(poly, format=’left’); L<br />

[6 1 0 0 0]<br />

[5 0 1 0 0]<br />

[4 0 0 1 0]<br />

[3 0 0 0 1]<br />

[2 0 0 0 0]<br />

sage: B = companion_matrix(poly, format=’bottom’); B<br />

[0 1 0 0 0]<br />

26 Chapter 2. Matrix Constructor

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

Saved successfully!

Ooh no, something went wrong!