12.07.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices

Sage Reference Manual: Matrices and Spaces of Matrices

Sage Reference Manual: Matrices and Spaces of Matrices

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.24.diagonal_matrix(ring, nrows, entries)INPUT:•entries - the values to place along the diagonal <strong>of</strong> the returned matrix. This may be a flat list, a flattuple, a vector or free module element, or a one-dimensional NumPy array.•nrows - the size <strong>of</strong> the returned matrix, which will have an equal number <strong>of</strong> columns•ring - the ring containing the entries <strong>of</strong> the diagonal entries. This may not be specified in combinationwith a NumPy array.•sparse - default: True - whether or not the result has a sparse implementation.OUTPUT:A square matrix over the given ring with a size given by nrows. If the ring is not given it is inferred from thegiven entries. The values on the diagonal <strong>of</strong> the returned matrix come from entries. If the number <strong>of</strong> entriesis not enough to fill the whole diagonal, it is padded with zeros.EXAMPLES:We first demonstrate each <strong>of</strong> the input formats with various different ways to specify the entries.Format 1: a flat list <strong>of</strong> entries.sage: A = diagonal_matrix([2, 1.3, 5]); A[ 2.00000000000000 0.000000000000000 0.000000000000000][0.000000000000000 1.30000000000000 0.000000000000000][0.000000000000000 0.000000000000000 5.00000000000000]sage: A.parent()Full MatrixSpace <strong>of</strong> 3 by 3 sparse matrices over Real Field with 53 bits <strong>of</strong> precisionFormat 2: size specified, a tuple with initial entries. Note that a short list <strong>of</strong> entries is effectively padded withzeros.sage: A = diagonal_matrix(3, (4, 5)); A[4 0 0][0 5 0][0 0 0]sage: A.parent()Full MatrixSpace <strong>of</strong> 3 by 3 sparse matrices over Integer RingFormat 3: ring specified, a vector <strong>of</strong> entries.sage: A = diagonal_matrix(QQ, vector(ZZ, [1,2,3])); A[1 0 0][0 2 0][0 0 3]sage: A.parent()Full MatrixSpace <strong>of</strong> 3 by 3 sparse matrices over Rational FieldFormat 4: ring, size <strong>and</strong> list <strong>of</strong> entries.sage: A = diagonal_matrix(FiniteField(3), 3, [2, 16]); A[2 0 0][0 1 0][0 0 0]sage: A.parent()Full MatrixSpace <strong>of</strong> 3 by 3 sparse matrices over Finite Field <strong>of</strong> size 3NumPy arrays may be used as input.29

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

Saved successfully!

Ooh no, something went wrong!