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

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

•eps - default: None - the largest number which will be considered to be zero. May also be set to the<br />

string ‘auto’. See the discussion below.<br />

OUTPUT:<br />

A sorted list <strong>of</strong> the singular values <strong>of</strong> the matrix, which are the diagonal entries <strong>of</strong> the “S” matrix in the<br />

SVD decomposition. As such, the values are real <strong>and</strong> are returned as elements <strong>of</strong> RDF. The list is sorted<br />

with larger values first, <strong>and</strong> since theory predicts these values are always positive, for a rank-deficient<br />

matrix the list should end in zeros (but in practice may not). The length <strong>of</strong> the list is the minimum <strong>of</strong> the<br />

row count <strong>and</strong> column count for the matrix.<br />

The number <strong>of</strong> non-zero singular values will be the rank <strong>of</strong> the matrix. However, as a numerical matrix, it is<br />

impossible to control the difference between zero entries <strong>and</strong> very small non-zero entries. As an informed<br />

consumer it is up to you to use the output responsibly. We will do our best, <strong>and</strong> give you the tools to work<br />

with the output, but we cannot give you a guarantee.<br />

With eps set to None you will get the raw singular values <strong>and</strong> can manage them as you see fit. You<br />

may also set eps to any positive floating point value you wish. If you set eps to ‘auto’ this routine<br />

will compute a reasonable cut<strong>of</strong>f value, based on the size <strong>of</strong> the matrix, the largest singular value <strong>and</strong> the<br />

smallest nonzero value representable by the 53-bit precision values used. See the discussion at page 268<br />

<strong>of</strong> [WATKINS].<br />

See the examples for a way to use the “verbose” facility to easily watch the zero cut<strong>of</strong>fs in action.<br />

ALGORITHM:<br />

The singular values come from the SVD decomposition computed by SciPy/NumPy.<br />

EXAMPLES:<br />

Singular values close to zero have trailing digits that may vary on different hardware. For exact matrices,<br />

the number <strong>of</strong> non-zero singular values will equal the rank <strong>of</strong> the matrix. So for some <strong>of</strong> the doctests we<br />

round the small singular values that ideally would be zero, to control the variability across hardware.<br />

This matrix has a determinant <strong>of</strong> one. A chain <strong>of</strong> two or three theorems implies the product <strong>of</strong> the singular<br />

values must also be one.<br />

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

... [-2, 1, 1, -2, 0, -4, 0],<br />

... [ 1, 0, 1, -4, -6, -3, 7],<br />

... [-2, 2, 1, 1, 7, 1, -1],<br />

... [-1, 0, -1, 5, 8, 4, -6],<br />

... [ 4, -2, -2, 1, -3, 0, 8],<br />

... [-2, 1, 0, 2, 7, 3, -4]])<br />

sage: A.determinant()<br />

1<br />

sage: B = A.change_ring(RDF)<br />

sage: sv = B.singular_values(); sv<br />

[20.5239806589, 8.48683702854, 5.86168134845, 2.44291658993,<br />

0.583197014472, 0.269332872866, 0.00255244880761]<br />

sage: prod(sv)<br />

1.0<br />

An exact matrix that is obviously not <strong>of</strong> full rank, <strong>and</strong> then a computation <strong>of</strong> the singular values after<br />

conversion to an approximate matrix.<br />

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

... [2/3, 1/3, 7/3],<br />

... [2/3, 5/3, 27/3]])<br />

sage: A.rank()<br />

2<br />

387

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

Saved successfully!

Ooh no, something went wrong!