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

[0.857142857142857 0.875000000000000 0.888888888888889]<br />

[0.900000000000000 0.909090909090909 0.916666666666667]<br />

QR(full=True)<br />

Returns a factorization <strong>of</strong> self as a unitary matrix <strong>and</strong> an upper-triangular matrix.<br />

INPUT:<br />

•full - default: True - if True then the returned matrices have dimensions as described below. If<br />

False the R matrix has no zero rows <strong>and</strong> the columns <strong>of</strong> Q are a basis for the column space <strong>of</strong> self.<br />

OUTPUT:<br />

If self is an m × n matrix <strong>and</strong> full=True then this method returns a pair <strong>of</strong> matrices: Q is an m × m<br />

unitary matrix (meaning its inverse is its conjugate-transpose) <strong>and</strong> R is an m × n upper-triangular matrix<br />

with non-negative entries on the diagonal. For a matrix <strong>of</strong> full rank this factorization is unique (due to the<br />

restriction to positive entries on the diagonal).<br />

If full=False then Q has m rows <strong>and</strong> the columns form an orthonormal basis for the column space <strong>of</strong><br />

self. So, in particular, the conjugate-transpose <strong>of</strong> Q times Q will be an identity matrix. The matrix R<br />

will still be upper-triangular but will also have full rank, in particular it will lack the zero rows present in<br />

a full factorization <strong>of</strong> a rank-deficient matrix.<br />

The results obtained when full=True are cached, hence Q <strong>and</strong> R are immutable matrices in this case.<br />

Note: This is an exact computation, so limited to exact rings. Also the base ring needs to have a fraction<br />

field implemented in <strong>Sage</strong> <strong>and</strong> this field must contain square roots. One example is the field <strong>of</strong> algebraic<br />

numbers, QQbar, as used in the examples below. If you need numerical results, convert the base ring to<br />

the field <strong>of</strong> complex double numbers, CDF, which will use a faster routine that is careful about numerical<br />

subtleties.<br />

ALGORITHM:<br />

“Modified Gram-Schmidt,” Algorithm 8.1 <strong>of</strong> [TREFETHEN-BAU].<br />

EXAMPLES:<br />

For a nonsingular matrix, the QR decomposition is unique.<br />

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

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

... [1, 1, 7, 4, 5],<br />

... [3, 0, 8, 3, 3],<br />

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

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

sage: Q<br />

[ -0.4588314677411235 -0.1260506983326509 0.3812120831224489 -0.394573711338418<br />

[ -0.4588314677411235 0.4726901187474409 -0.05198346588033394 0.717294125164660<br />

[ 0.2294157338705618 0.6617661662464172 0.6619227988762521 -0.180872093737548<br />

[ 0.6882472016116853 0.1890760474989764 -0.2044682991293135 0.096630296654307<br />

[ -0.2294157338705618 0.5357154679137663 -0.609939332995919 -0.536422031427112<br />

sage: R<br />

[ 4.358898943540674 -0.4588314677411235 13.07669683062202 6.194224814505168 2.982<br />

[ 0 1.670171752907625 0.5987408170800917 -1.292019657909672 6.207<br />

[ 0 0 5.444401659866974 5.468660610611130 -0.682<br />

[ 0 0 0 1.027626039419836 -3.61<br />

[ 0 0 0 0 0.02<br />

sage: Q.conjugate_transpose()*Q<br />

[1.000000000000000 0.e-18 0.e-17 0.e-15 0.e<br />

[ 0.e-18 1.000000000000000 0.e-16 0.e-15 0.e<br />

127

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

Saved successfully!

Ooh no, something went wrong!