Compute the QR factorization of a, using standard Lapack subroutines. For example, given the matrix
a = [1, 2; 3, 4],[q, r] = qr (a)returns
q = -0.31623 -0.94868 -0.94868 0.31623 r = -3.16228 -4.42719 0.00000 -0.63246The
qrfactorization has applications in the solution of least squares problems for overdetermined systems of equations (i.e., is a tall, thin matrix). The QR factorization isIf given a second argument of '0',
qrreturns an economy-sized QR factorization, omitting zero rows of R and the corresponding columns of Q.If the matrix a is full, the permuted QR factorization
[q,r,p] = qr (a)forms the QR factorization such that the diagonal entries ofrare decreasing in magnitude order. For example,given the matrixa = [1, 2; 3, 4],[q, r, p] = qr(a)returns
q = -0.44721 -0.89443 -0.89443 0.44721 r = -4.47214 -3.13050 0.00000 0.44721 p = 0 1 1 0The permuted
qrfactorization[q, r, p] = qr (a)factorization allows the construction of an orthogonal basis ofspan (a).If the matrix a is sparse, then compute the sparse QR factorization of a, using CSparse. As the matrix Q is in general a full matrix, this function returns the Q-less factorization r of a, such that r
= chol (a' *a).If the final argument is the scalar
0and the number of rows is larger than the number of columns, then an economy factorization is returned. That is r will have onlysize (a,1)rows.If an additional matrix b is supplied, then
qrreturns c, where c=q' *b. This allows the least squares approximation of a\b to be calculated as[c,r] = spqr (a,b) x = r \ c