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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<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.2sage: A = matrix(2, 3, range(6))sage: B = matrix(3, 3, range(9))sage: block_matrix([A, A, A, B, B, B])Traceback (most recent call last):...ValueError: must specify nrows or ncols for non-square block matrix.sage.matrix.constructor.column_matrix(*args, **kwds)This function is available as column_matrix(...) <strong>and</strong> matrix.column(...).Constructs a matrix, <strong>and</strong> then swaps rows for columns <strong>and</strong> columns for rows.Note: Linear algebra in <strong>Sage</strong> favors rows over columns. So, generally, when creating a matrix, input vectors<strong>and</strong> lists are treated as rows. This function is a convenience that turns around this convention when creating amatrix. If you are not familiar with the usual matrix constructor, you might want to consider it first.INPUT:Inputs are almost exactly the same as for the matrix constructor, which are documented there. But see examplesbelow for how dimensions are h<strong>and</strong>led.OUTPUT:Output is exactly the transpose <strong>of</strong> what the matrix constructor would return. In other words, the matrixconstructor builds a matrix <strong>and</strong> then this function exchanges rows for columns, <strong>and</strong> columns for rows.EXAMPLES:The most compelling use <strong>of</strong> this function is when you have a collection <strong>of</strong> lists or vectors that you would liketo become the columns <strong>of</strong> a matrix. In almost any other situation, the matrix constructor can probably do thejob just as easily, or easier.sage: col_1 = [1,2,3]sage: col_2 = [4,5,6]sage: column_matrix([col_1, col_2])[1 4][2 5][3 6]sage: v1 = vector(QQ, [10, 20])sage: v2 = vector(QQ, [30, 40])sage: column_matrix(QQ, [v1, v2])[10 30][20 40]If you only specify one dimension along with a flat list <strong>of</strong> entries, then it will be the number <strong>of</strong> columns in theresult (which is different from the behavior <strong>of</strong> the matrix constructor).sage: column_matrix(ZZ, 8, range(24))[ 0 3 6 9 12 15 18 21][ 1 4 7 10 13 16 19 22][ 2 5 8 11 14 17 20 23]And when you specify two dimensions, then they should be number <strong>of</strong> columns first, then the number <strong>of</strong> rows,which is the reverse <strong>of</strong> how they would be specified for the matrix constructor.sage: column_matrix(QQ, 5, 3, range(15))[ 0 3 6 9 12][ 1 4 7 10 13][ 2 5 8 11 14]25

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

Saved successfully!

Ooh no, something went wrong!