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

[ 4.358899 -0.458831 13.076697 6.194225 2.982405]<br />

[ 0.0 1.670172 0.598741 -1.29202 6.207997]<br />

[ 0.0 0.0 5.444402 5.468661 -0.682716]<br />

[ 0.0 0.0 0.0 1.027626 -3.6193]<br />

[ 0.0 0.0 0.0 0.0 0.024551]<br />

sage: (Q*Q.transpose()).zero_at(10^-14)<br />

[1.0 0.0 0.0 0.0 0.0]<br />

[0.0 1.0 0.0 0.0 0.0]<br />

[0.0 0.0 1.0 0.0 0.0]<br />

[0.0 0.0 0.0 1.0 0.0]<br />

[0.0 0.0 0.0 0.0 1.0]<br />

sage: (Q*R - A).zero_at(10^-14)<br />

[0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0 0.0]<br />

Now over the complex numbers, demonstrating that the SciPy libraries are (properly) using the Hermitian<br />

inner product, so that Q is a unitary matrix (its inverse is the conjugate-transpose).<br />

sage: A = matrix(CDF, [[-8, 4*I + 1, -I + 2, 2*I + 1],<br />

... [1, -2*I - 1, -I + 3, -I + 1],<br />

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

... [I + 2, 0, I + 12, -1]])<br />

sage: Q, R = A.QR()<br />

sage: Q._normalize_columns().round(6).zero_at(10^-6)<br />

[ 0.730297 0.207057 + 0.538347*I 0.246305 - 0.076446*I 0.238162 - 0.10366*I<br />

[ -0.091287 -0.207057 - 0.377878*I 0.378656 - 0.195222*I 0.701244 - 0.364371*I<br />

[ -0.63901 - 0.091287*I 0.170822 + 0.667758*I -0.034115 + 0.040902*I 0.314017 - 0.082519*I<br />

[-0.182574 - 0.091287*I -0.036235 + 0.07247*I 0.863228 + 0.063228*I -0.449969 - 0.011612*I<br />

sage: R._normalize_rows().round(6).zero_at(10^-6)<br />

[ 10.954451 -1.917029*I 5.385938 - 2.19089*I -0.273861 - 2.19089*I<br />

[ 0.0 4.829596 -0.869638 - 5.864879*I 0.993872 - 0.305409*I<br />

[ 0.0 0.0 12.001608 -0.270953 + 0.442063*I<br />

[ 0.0 0.0 0.0 1.942964<br />

sage: (Q.conjugate().transpose()*Q).zero_at(10^-15)<br />

[1.0 0.0 0.0 0.0]<br />

[0.0 1.0 0.0 0.0]<br />

[0.0 0.0 1.0 0.0]<br />

[0.0 0.0 0.0 1.0]<br />

sage: (Q*R - A).zero_at(10^-14)<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

[0.0 0.0 0.0 0.0]<br />

An example <strong>of</strong> a rectangular matrix that is also rank-deficient. If you run this example yourself, you may<br />

see a very small, nonzero entries in the third row, in the third column, even though the exact version <strong>of</strong> the<br />

matrix has rank 2. The final two columns <strong>of</strong> Q span the left kernel <strong>of</strong> A (as evidenced by the two zero rows<br />

<strong>of</strong> R). Different platforms will compute different bases for this left kernel, so we do not exhibit the actual<br />

matrix.<br />

sage: Arat = matrix(QQ, [[2, -3, 3],<br />

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

... [-1, 3, -3],<br />

... [-5, 1, -1]])<br />

sage: Arat.rank()<br />

353

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

Saved successfully!

Ooh no, something went wrong!