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

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.1.1<br />

linear_combination_<strong>of</strong>_rows(v)<br />

Return the linear combination <strong>of</strong> the rows <strong>of</strong> self given by the coefficients in the list v.<br />

INPUT:<br />

•v - a list <strong>of</strong> scalars. The length can be less than the number <strong>of</strong> rows <strong>of</strong> self but not greater.<br />

OUTPUT:<br />

The vector (or free module element) that is a linear combination <strong>of</strong> the rows <strong>of</strong> self. If the list <strong>of</strong> scalars<br />

has fewer entries than the number <strong>of</strong> rows, additional zeros are appended to the list until it has as many<br />

entries as the number <strong>of</strong> rows.<br />

EXAMPLES:<br />

sage: a = matrix(ZZ,2,3,range(6)); a<br />

[0 1 2]<br />

[3 4 5]<br />

sage: a.linear_combination_<strong>of</strong>_rows([1,2])<br />

(6, 9, 12)<br />

sage: a.linear_combination_<strong>of</strong>_rows([0,0])<br />

(0, 0, 0)<br />

sage: a.linear_combination_<strong>of</strong>_rows([1/2,2/3])<br />

(2, 19/6, 13/3)<br />

The list v can be anything that is iterable. Perhaps most naturally, a vector may be used.<br />

sage: v = vector(ZZ, [1,2])<br />

sage: a.linear_combination_<strong>of</strong>_rows(v)<br />

(6, 9, 12)<br />

We check that a matrix with no rows behaves properly.<br />

sage: matrix(QQ,0,2).linear_combination_<strong>of</strong>_rows([])<br />

(0, 0)<br />

The object returned is a vector, or a free module element.<br />

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

sage: w = B.linear_combination_<strong>of</strong>_rows([-1,2,-3,4])<br />

sage: w<br />

(24, 26, 28)<br />

sage: w.parent()<br />

Ambient free module <strong>of</strong> rank 3 over the principal ideal domain Integer Ring<br />

sage: x = B.linear_combination_<strong>of</strong>_rows([1/2,1/3,1/4,1/5])<br />

sage: x<br />

(43/10, 67/12, 103/15)<br />

sage: x.parent()<br />

Vector space <strong>of</strong> dimension 3 over Rational Field<br />

The length <strong>of</strong> v can be less than the number <strong>of</strong> rows, but not greater.<br />

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

sage: A.linear_combination_<strong>of</strong>_rows([2,3])<br />

(12, 17, 22, 27)<br />

sage: A.linear_combination_<strong>of</strong>_rows([1,2,3,4])<br />

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

...<br />

ValueError: length <strong>of</strong> v must be at most the number <strong>of</strong> rows <strong>of</strong> self<br />

81

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

Saved successfully!

Ooh no, something went wrong!