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

sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); v = vector([-1/2,-1])<br />

sage: x = A \ v; x<br />

(-1/2, 0, 0)<br />

sage: A*x == v<br />

True<br />

Same example but over Z:<br />

sage: A = matrix(ZZ,2,3, [1,2,3,2,4,6]); v = vector([-1,-2])<br />

sage: A \ v<br />

(-1, 0, 0)<br />

An example in which there is no solution:<br />

sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); v = vector([1,1])<br />

sage: A \ v<br />

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

...<br />

ValueError: matrix equation has no solutions<br />

A ValueError is raised if the input is invalid:<br />

sage: A = matrix(QQ,4,2, [0, -1, 1, 0, -2, 2, 1, 0])<br />

sage: B = matrix(QQ,2,2, [1, 0, 1, -1])<br />

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

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

...<br />

ValueError: number <strong>of</strong> rows <strong>of</strong> self must equal number <strong>of</strong> rows <strong>of</strong> B<br />

We solve with A singular:<br />

sage: A = matrix(QQ,2,3, [1,2,3,2,4,6]); B = matrix(QQ,2,2, [6, -6, 12, -12])<br />

sage: X = A.solve_right(B); X<br />

[ 6 -6]<br />

[ 0 0]<br />

[ 0 0]<br />

sage: A*X == B<br />

True<br />

We illustrate left associativity, etc., <strong>of</strong> the backslash operator.<br />

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

sage: A \ A<br />

[1 0]<br />

[0 1]<br />

sage: A \ A \ A<br />

[1 2]<br />

[3 4]<br />

sage: A.parent()(1) \ A<br />

[1 2]<br />

[3 4]<br />

sage: A \ (A \ A)<br />

[ -2 1]<br />

[ 3/2 -1/2]<br />

sage: X = A \ (A - 2); X<br />

[ 5 -2]<br />

[-3 2]<br />

sage: A * X<br />

[-1 2]<br />

[ 3 2]<br />

255

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

Saved successfully!

Ooh no, something went wrong!