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

Some subfields <strong>of</strong> the complex numbers, such as this number field <strong>of</strong> complex numbers with rational real<br />

<strong>and</strong> imaginary parts, allow for this computation.<br />

sage: C. = QuadraticField(-1)<br />

sage: A = matrix(C, [[ 23, 17*I + 3, 24*I + 25, 21*I],<br />

... [ -17*I + 3, 38, -69*I + 89, 7*I + 15],<br />

... [-24*I + 25, 69*I + 89, 976, 24*I + 6],<br />

... [ -21*I, -7*I + 15, -24*I + 6, 28]])<br />

sage: A.is_hermitian()<br />

True<br />

sage: L = A.cholesky()<br />

sage: L<br />

[ 4.79... 0 0 0]<br />

[ 0.62... - 3.54...*I 5.00... 0 0]<br />

[ 5.21... - 5.00...*I 13.58... + 10.72...*I 24.98... 0]<br />

[ -4.37...*I -0.10... - 0.85...*I -0.21... + 0.37...*I 2.81...]<br />

sage: L.parent()<br />

Full MatrixSpace <strong>of</strong> 4 by 4 dense matrices over Algebraic Field<br />

sage: (L*L.conjugate_transpose() - A.change_ring(QQbar)).norm() < 10^-10<br />

True<br />

The field <strong>of</strong> algebraic numbers is an ideal setting for this computation.<br />

sage: A = matrix(QQbar, [[ 2, 4 + 2*I, 6 - 4*I],<br />

... [ -2*I + 4, 11, 10 - 12*I],<br />

... [ 4*I + 6, 10 + 12*I, 37]])<br />

sage: A.is_hermitian()<br />

True<br />

sage: L = A.cholesky()<br />

sage: L<br />

[ 1.414213562373095 0 0]<br />

[2.828427124746190 - 1.414213562373095*I 1 0]<br />

[4.242640687119285 + 2.828427124746190*I -2*I + 2 1.732050807568878]<br />

sage: L.parent()<br />

Full MatrixSpace <strong>of</strong> 3 by 3 dense matrices over Algebraic Field<br />

sage: (L*L.conjugate_transpose() - A.change_ring(QQbar)).norm() < 10^-10<br />

True<br />

Results are cached, hence immutable. Use the copy function if you need to make a change.<br />

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

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

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

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

sage: L = A.cholesky()<br />

sage: L.is_immutable()<br />

True<br />

sage: from copy import copy<br />

sage: LC = copy(L)<br />

sage: LC[0,0] = 1000<br />

sage: LC<br />

[1000 0 0 0]<br />

[ -1 3 0 0]<br />

[ 2 0 2 0]<br />

[ 1 -2 1 1]<br />

There are a variety <strong>of</strong> situations which will prevent the computation <strong>of</strong> a Cholesky decomposition.<br />

The base ring must be exact. For numerical work, create a matrix with a base ring <strong>of</strong> RDF or CDF <strong>and</strong> use<br />

136 Chapter 7. Base class for matrices, part 2

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

Saved successfully!

Ooh no, something went wrong!