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

The vector <strong>of</strong> constants, b, can be given in a variety <strong>of</strong> forms, so long as it coerces to a vector over the<br />

same base ring as the coefficient matrix.<br />

sage: A=matrix(CDF, 5, [1/(i+j+1) for i in range(5) for j in range(5)])<br />

sage: A.solve_left([1]*5) # rel tol 1e-11<br />

(5.0, -120.0, 630.0, -1120.0, 630.0)<br />

TESTS:<br />

A degenerate case.<br />

sage: A = matrix(RDF, 0, 0, [])<br />

sage: A.solve_left(vector(RDF,[]))<br />

()<br />

The coefficent matrix must be square.<br />

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

sage: b = vector(RDF, [1,2,3])<br />

sage: A.solve_left(b)<br />

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

...<br />

ValueError: coefficient matrix <strong>of</strong> a system over RDF/CDF must be square, not 2 x 3<br />

The coefficient matrix must be nonsingular.<br />

sage: A = matrix(RDF, 5, range(25))<br />

sage: b = vector(RDF, [1,2,3,4,5])<br />

sage: A.solve_left(b)<br />

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

...<br />

LinAlgError: singular matrix<br />

The vector <strong>of</strong> constants needs the correct degree.<br />

sage: A = matrix(RDF, 5, range(25))<br />

sage: b = vector(RDF, [1,2,3,4])<br />

sage: A.solve_left(b)<br />

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

...<br />

TypeError: vector <strong>of</strong> constants over Real Double Field incompatible with matrix over Real Dou<br />

The vector <strong>of</strong> constants needs to be compatible with the base ring <strong>of</strong> the coefficient matrix.<br />

sage: F. = FiniteField(27)<br />

sage: b = vector(F, [a,a,a,a,a])<br />

sage: A.solve_left(b)<br />

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

...<br />

TypeError: vector <strong>of</strong> constants over Finite Field in a <strong>of</strong> size 3^3 incompatible with matrix o<br />

With a coefficient matrix over RDF, a vector <strong>of</strong> constants over CDF can be accomodated by converting the<br />

base ring <strong>of</strong> the coefficient matrix.<br />

sage: A = matrix(RDF, 2, range(4))<br />

sage: b = vector(CDF, [1+I,2])<br />

sage: A.solve_left(b)<br />

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

...<br />

TypeError: vector <strong>of</strong> constants over Complex Double Field incompatible with matrix over Real<br />

390 Chapter 19. Dense matrices using a NumPy backend.

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

Saved successfully!

Ooh no, something went wrong!