1
<?xml version="1.0" encoding="UTF-8"?>
3
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4
* Copyright (C) 2008 - INRIA
6
* This file must be used under the terms of the CeCILL.
7
* This source file is licensed as described in the file COPYING, which
8
* you should have received as part of this distribution. The terms
9
* are also available at
10
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en" xml:id="qr">
16
<refpurpose> QR decomposition</refpurpose>
19
<title>Calling Sequence</title>
20
<synopsis>[Q,R]=qr(X [,"e"])
22
[Q,R,rk,E]=qr(X [,tol])
26
<title>Arguments</title>
31
<para>real or complex matrix</para>
37
<para>nonnegative real number</para>
43
<para>square orthogonal or unitary matrix</para>
50
matrix with same dimensions as <literal>X</literal>
57
<para>permutation matrix</para>
64
integer (QR-rank of <literal>X</literal>)
71
<title>Description</title>
74
<term>[Q,R] = qr(X)</term>
77
produces an upper triangular matrix <literal>R</literal> of the same dimension as <literal>X</literal> and an orthogonal (unitary in the complex case) matrix <literal>Q</literal> so that <literal>X = Q*R</literal>. <literal>[Q,R] = qr(X,"e")</literal> produces an "economy size": If <literal>X</literal> is m-by-n with m > n, then only the first n columns of <literal>Q</literal> are computed as well as the first n rows of <literal>R</literal>.
80
From <literal>Q*R = X</literal> , it follows that
81
the kth column of the matrix <literal>X</literal>, is expressed as a linear combination
82
of the k first columns of <literal>Q</literal> (with coefficients <literal> R(1,k), ..., R(k,k) </literal>). The k first columns of <literal>Q</literal> make an orthogonal basis
83
of the subspace spanned by the k first comumns of <literal>X</literal>. If column <literal>k</literal>
84
of <literal>X</literal> (i.e. <literal>X(:,k)</literal> ) is a linear combination of the first
85
<literal>p</literal> columns of <literal>X</literal>, then the entries <literal>R(p+1,k), ..., R(k,k)</literal>
86
are zero. It this situation, <literal>R</literal> is upper trapezoidal. If <literal>X</literal> has
87
rank <literal>rk</literal>, rows <literal>R(rk+1,:), R(rk+2,:), ...</literal> are zeros.
92
<term>[Q,R,E] = qr(X)</term>
95
produces a (column) permutation matrix <literal>E</literal>, an upper
96
triangular <literal>R</literal> with decreasing diagonal elements and an
97
orthogonal (or unitary) <literal>Q</literal> so that <literal>X*E = Q*R</literal>.
98
If <literal>rk</literal> is the rank of <literal>X</literal>, the
99
<literal>rk</literal> first entries along the main diagonal of
100
<literal>R</literal>, i.e. <literal>R(1,1), R(2,2), ..., R(rk,rk)</literal>
101
are all different from zero. <literal>[Q,R,E] = qr(X,"e")</literal>
102
produces an "economy size":
103
If <literal>X</literal> is m-by-n with m > n, then only the first n
104
columns of <literal>Q</literal> are computed as well as the first n
105
rows of <literal>R</literal>.
110
<term>[Q,R,rk,E] = qr(X ,tol)</term>
113
returns <literal>rk</literal> = rank estimate of <literal>X</literal> i.e. <literal>rk</literal> is the number of diagonal elements in <literal>R</literal> which are larger than a given threshold <literal>tol</literal>.
118
<term>[Q,R,rk,E] = qr(X) </term>
121
returns <literal>rk</literal> = rank estimate of <literal>X</literal>
122
i.e. <literal>rk</literal> is the number of diagonal elements in
123
<literal>R</literal> which are larger than
124
<literal>tol=R(1,1)*%eps*max(size(R))</literal>. See <literal>rankqr</literal>
125
for a rank revealing QR factorization, using the condition number
126
of <literal>R</literal>.
133
<title>Examples</title>
134
<programlisting role="example"><![CDATA[
135
// QR factorization, generic case
136
// X is tall (full rank)
137
X=rand(5,2);[Q,R]=qr(X); [Q'*X R]
139
//X is fat (full rank)
140
X=rand(2,3);[Q,R]=qr(X); [Q'*X R]
142
//Column 4 of X is a linear combination of columns 1 and 2:
143
X=rand(8,5);X(:,4)=X(:,1)+X(:,2); [Q,R]=qr(X); R, R(:,4)
145
//X has rank 2, rows 3 to $ of R are zero:
146
X=rand(8,2)*rand(2,5);[Q,R]=qr(X); R
148
//Evaluating the rank rk: column pivoting ==> rk first
149
//diagonal entries of R are non zero :
150
A=rand(5,2)*rand(2,5);
151
[Q,R,rk,E] = qr(A,1.d-10);
153
svd([A,Q(:,1:rk)]) //span(A) =span(Q(:,1:rk))
156
<refsection role="see also">
157
<title>See Also</title>
158
<simplelist type="inline">
160
<link linkend="rankqr">rankqr</link>
163
<link linkend="rank">rank</link>
166
<link linkend="svd">svd</link>
169
<link linkend="rowcomp">rowcomp</link>
172
<link linkend="colcomp">colcomp</link>
177
<title>Used Functions</title>
179
qr decomposition is based the Lapack routines DGEQRF, DGEQPF,
180
DORGQR for the real matrices and ZGEQRF, ZGEQPF, ZORGQR for the