# Orthogonal Factorizations

This topic describes the LAPACK routines for the QR (RQ) and LQ (QL) factorization of matrices. Routines for the RZ factorization as well as for generalized QR and RQ factorizations are also included.

QR Factorization. Assume that A is an m-by-n matrix to be factored.

If m ≥ n, the QR factorization is given by

where R is an n-by-n upper triangular matrix with real diagonal elements, and Q is an m-by-m orthogonal (or unitary) matrix.

You can use the QR factorization for solving the following least squares problem: minimize `||Ax - b||2` where A is a full-rank m-by-n matrix (`m≥n`). After factoring the matrix, compute the solution x by solving `Rx = (Q1)Tb`.

If `m < n`, the QR factorization is given by

`A = QR = Q(R1R2)`

where R is trapezoidal, R1 is upper triangular and R2 is rectangular.

The LAPACK routines do not form the matrix Q explicitly. Instead, Q is represented as a product of min(m, n) elementary reflectors. Routines are provided to work with Q in this representation.

LQ Factorization LQ factorization of an m-by-n matrix A is as follows. If m ≤ n,

where L is an m-by-m lower triangular matrix with real diagonal elements, and Q is an n-by-n orthogonal (or unitary) matrix.

If `m > n`, the LQ factorization is

where L1 is an n-by-n lower triangular matrix, L2 is rectangular, and Q is an n-by-n orthogonal (or unitary) matrix.

You can use the LQ factorization to find the minimum-norm solution of an underdetermined system of linear equations `Ax = b` where A is an m-by-n matrix of rank `m (m < n)`. After factoring the matrix, compute the solution vector x as follows: solve `Ly = b` for y, and then compute `x = (Q1)Hy`.

Table “Computational Routines for Orthogonal Factorization” lists LAPACK routines (Fortran 77 interface) that perform orthogonal factorization of matrices. Respective routine names in Fortran 95 interface are without the first symbol (see Routine Naming Conventions).

Computational Routines for Orthogonal Factorization
Matrix type, factorization | Factorize without pivoting | Factorize with pivoting | Generate matrix Q | Apply matrix Q
--- | --- | --- | --- | ---
general matrices, QR factorization | ?geqrf | ?geqpf ?geqp3 | ?orgqr ?ungqr | ?ormqr ?unmqr
general matrices, RQ factorization | ?gerqf |  | ?orgrq ?ungrq | ?ormrq ?unmrq
general matrices, LQ factorization | ?gelqf |  | ?orglq ?unglq | ?ormlq ?unmlq
general matrices, QL factorization | ?geqlf |  | ?orgql ?ungql | ?ormql ?unmql
trapezoidal matrices, RZ factorization | ?tzrzf |  |  | ?ormrz ?unmrz
pair of matrices, generalized QR factorization | ?ggqrf |  |  |
pair of matrices, generalized RQ factorization | ?ggrqf |  |  |