1. Home
  2. QRD directive

QRD directive

Calculates QR decompositions of matrices.

Option

PRINT = string tokens Printed output required (orthogonalmatrix, uppertriangularmatrix); default * i.e. no printing

Parameters

INMATRIX = matrices or symmetric matrices Matrices to be decomposed
ORTHOGONALMATRIX = matrices Orthogonal matrix of each decomposition
UPPERTRIANGULARMATRIX= matrices Upper-triangular matrix of each decomposition

Description

The QR decomposition of a matrix is a decomposition of an m by n matrix A into an orthogonal matrix Q (i.e. QQ = I), and an n by m matrix R, so that A = Q R. If m ≥ n, the top n rows of R are triangular and the lower mn rows contain zeros. If m < n, R is trapezoidal, i.e. it has the form (R1 | R2) where R1 is an upper triangular matrix and R2 is a rectangular matrix.

The matrix A to be composed is specified by the INMATRIX parameter, and the matrices Q and R can be saved using the ORTHOGONALMATRIX, and UPPERTRIANGULARMATRIX parameters, respectively.

The PRINT option allows you to print either of the components of the decomposition; by default, nothing is printed.

Option: PRINT.

Parameters: INMATRIX, ORTHOGONALMATRIX, UPPERTRIANGULARMATRIX.

Method

QRD uses subroutines F08AEF and F08AFF from the NAG Library.

See also

Directives: MATRIX, CALCULATE, NAG, FLRV, SVD.

Commands for: Calculations and manipulation,

Multivariate and cluster analysis.

Example

" Example QRD-1: NAG example for F08AEF "
MATRIX    [ROWS=6; COLUMNS=4; VALUES=\
          -0.57, -1.28, -0.39,  0.25,\
          -1.93,  1.08, -0.31, -2.14,\
           2.30,  0.24,  0.40, -0.35,\
          -1.93,  0.64, -0.66,  0.08,\
           0.15,  0.30,  0.15, -2.13,\
          -0.02,  1.03, -1.43,  0.50] A
QRD       A; ORTHOGONALMATRIX=Q; UPPERTRIANGULARMATRIX=R
PRINT     Q,R
" verify that A = QR "
CALCULATE QR = Q *+ R
PRINT     [RLWIDTH=2] A,QR; FIELD=9
" verify that Q'Q = I "
CALCULATE QQ = T(Q) *+ Q
PRINT     QQ
" solve the linear least-squares problem:
  minimize (Axi - Bi)**2: i=1,2 "
MATRIX    [ROW=6; COLUMNS=2; VALUES=\
          -3.15,  2.19,\
          -0.11, -3.64,\
           1.99,  0.57,\
          -2.70,  8.23,\
           0.26, -6.35,\
           4.50, -1.48] B
CALCULATE C = T(Q) *+ B
&         X = GINVERSE(R) *+ C
PRINT     X
" check vs. ordinary regression "
VARIATE   B1,B2; VALUES=B$[*;1,2]
&         A1,A2,A3,A4; VALUES=A$[*;1...4]
MODEL     B1,B2
FIT       [PRINT=estimates; CONSTANT=omit] A1,A2,A3,A4
Updated on June 19, 2019

Was this article helpful?