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: B = A.change_ring(CDF)<br />

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

sage: sv[0:2]<br />

[10.1973039..., 0.487045871...]<br />

sage: sv[2] < 1e-14<br />

True<br />

A matrix <strong>of</strong> rank 3 over the complex numbers.<br />

sage: A = matrix(CDF, [[46*I - 28, -47*I - 50, 21*I + 51, -62*I - 782, 13*I + 22],<br />

... [35*I - 20, -32*I - 46, 18*I + 43, -57*I - 670, 7*I + 3],<br />

... [22*I - 13, -23*I - 23, 9*I + 24, -26*I - 347, 7*I + 13],<br />

... [-44*I + 23, 41*I + 57, -19*I - 54, 60*I + 757, -11*I - 9],<br />

... [30*I - 18, -30*I - 34, 14*I + 34, -42*I - 522, 8*I + 12]])<br />

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

sage: sv[0:3]<br />

[1440.733666, 18.4044034134, 6.83970779714]<br />

sage: (10^-15 < sv[3]) <strong>and</strong> (sv[3] < 10^-13)<br />

True<br />

sage: (10^-16 < sv[4]) <strong>and</strong> (sv[4] < 10^-14)<br />

True<br />

A full-rank matrix that is ill-conditioned. We use this to illustrate ways <strong>of</strong> using the various possibilities for<br />

eps, including one that is ill-advised. Notice that the automatically computed cut<strong>of</strong>f gets this (difficult)<br />

example slightly wrong. This illustrates the impossibility <strong>of</strong> any automated process always getting this<br />

right. Use with caution <strong>and</strong> judgement.<br />

sage: entries = [1/(i+j+1) for i in range(12) for j in range(12)]<br />

sage: B = matrix(QQ, 12, 12, entries)<br />

sage: B.rank()<br />

12<br />

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

sage: A.condition() > 1.6e16 or A.condition()<br />

True<br />

sage: A.singular_values(eps=None) # abs tol 1e-16<br />

[1.79537205956, 0.380275245955, 0.0447385487522, 0.00372231223789, 0.000233089089022, 1.1163<br />

sage: A.singular_values(eps=’auto’) # abs tol 1e-16<br />

[1.79537205956, 0.380275245955, 0.0447385487522, 0.00372231223789, 0.000233089089022, 1.1163<br />

sage: A.singular_values(eps=1e-4)<br />

[1.79537205956, 0.380275245955, 0.0447385487522, 0.00372231223789, 0.000233089089022, 0.0, 0<br />

With <strong>Sage</strong>’s “verbose” facility, you can compactly see the cut<strong>of</strong>f at work. In any application <strong>of</strong> this routine,<br />

or those that build upon it, it would be a good idea to conduct this exercise on samples. We also test here<br />

that all the values are returned in RDF since singular values are always real.<br />

sage: A = matrix(CDF, 4, range(16))<br />

sage: set_verbose(1)<br />

sage: sv = A.singular_values(eps=’auto’); sv<br />

verbose 1 () singular values,<br />

smallest-non-zero:cut<strong>of</strong>f:largest-zero,<br />

2.2766...:6.2421...e-14:...<br />

[35.139963659, 2.27661020871, 0.0, 0.0]<br />

sage: set_verbose(0)<br />

sage: all([s in RDF for s in sv])<br />

True<br />

388 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!