QR decomposition

next - skip - up - start

This is a variant on the usual QR transformation.

Start with matrix

       / 0    0 \      s
       \ X    Y /      n

         s    t
Our version of the QR decomposition multiplies this matrix by an orthogonal matrix Q to get
       / U    M \      s
       \ 0    Z /      n

         s    t
where U is upper triangular (the R of the QR transform).

This is good for solving least squares problems: choose b (matrix or row vector) to minimize the sum of the squares of the elements of

         Y - X*b
Then choose b = U.i()*M; The residuals Y - X*b are in Z.

This is the usual QR transformation applied to the matrix X with the square zero matrix attached concatenated on top of it. It gives the same triangular matrix as the QR transform applied directly to X and generally seems to work in the same way as the usual QR transform. However it fits into the matrix package better and also gives us the residuals directly. It turns out to be essentially a modified Gram-Schmidt decomposition.

Two routines are provided:

    QRZ(X, U);
replaces X by orthogonal columns and forms U.
    QRZ(X, Y, M);
uses X from the first routine, replaces Y by Z and forms M.

The are also two routines QRZT(X, L) and QRZT(X, Y, M) which do the same decomposition on the transposes of all these matrices. QRZT replaces the routines HHDecompose in earlier versions of newmat. HHDecompose is still defined but just calls QRZT.