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

INPUT:<br />

•A – a matrix<br />

OUTPUT:<br />

•U, S, V – immutable matrices such that A = U ∗ S ∗ V.conj().transpose() where U <strong>and</strong> V are<br />

orthogonal <strong>and</strong> S is zero <strong>of</strong>f <strong>of</strong> the diagonal.<br />

Note that if self is m-by-n, then the dimensions <strong>of</strong> the matrices that this returns are (m,m), (m,n), <strong>and</strong> (n,<br />

n).<br />

Note: If all you need is the singular values <strong>of</strong> the matrix, see the more convenient<br />

singular_values().<br />

EXAMPLES:<br />

sage: m = matrix(RDF,4,range(1,17))<br />

sage: U,S,V = m.SVD()<br />

sage: U*S*V.transpose()<br />

[ 1.0 2.0 3.0 4.0]<br />

[ 5.0 6.0 7.0 8.0]<br />

[ 9.0 10.0 11.0 12.0]<br />

[13.0 14.0 15.0 16.0]<br />

A non-square example:<br />

sage: m = matrix(RDF, 2, range(1,7)); m<br />

[1.0 2.0 3.0]<br />

[4.0 5.0 6.0]<br />

sage: U, S, V = m.SVD()<br />

sage: U*S*V.transpose()<br />

[1.0 2.0 3.0]<br />

[4.0 5.0 6.0]<br />

S contains the singular values:<br />

sage: S.round(4)<br />

[ 9.508 0.0 0.0]<br />

[ 0.0 0.7729 0.0]<br />

sage: [round(sqrt(abs(x)),4) for x in (S*S.transpose()).eigenvalues()]<br />

[9.508, 0.7729]<br />

U <strong>and</strong> V are orthogonal matrices:<br />

sage: U # r<strong>and</strong>om, SVD is not unique<br />

[-0.386317703119 -0.922365780077]<br />

[-0.922365780077 0.386317703119]<br />

[-0.274721127897 -0.961523947641]<br />

[-0.961523947641 0.274721127897]<br />

sage: (U*U.transpose()).zero_at(1e-15)<br />

[1.0 0.0]<br />

[0.0 1.0]<br />

sage: V # r<strong>and</strong>om, SVD is not unique<br />

[-0.428667133549 0.805963908589 0.408248290464]<br />

[-0.566306918848 0.112382414097 -0.816496580928]<br />

[-0.703946704147 -0.581199080396 0.408248290464]<br />

sage: (V*V.transpose()).zero_at(1e-15)<br />

[1.0 0.0 0.0]<br />

355

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

Saved successfully!

Ooh no, something went wrong!