QR Factorization
Learn how QR factorization of matrices works, using R, Rcpp, Armadillo, and Eigen.
QR decomposition
QR decomposition, or factorization, is a decomposition of a matrix into the product of an orthogonal matrix and an upper triangular matrix :
Orthogonal matrix
An orthogonal matrix is a square matrix where the columns and rows are orthogonal unit vectors (orthonormal vectors), such that:
In this equation, is the identity matrix. This leads to the equivalent characterizationβa matrix is orthogonal if its transpose is equal to its inverse.
Note: A vector is said to be normal if it has a length of one. Two vectors are said to be orthogonal if theyβre at right angles to each other (in other words, their dot product is equal to zero). A set of vectors is said to be orthonormal if theyβre all normal and each pair of vectors in the set is orthogonal.
This factorization is applicable to both square and generic rectangular matrices. In the latter case, matrix of size with is decomposed in the product of , which is size , and , which is , so that:
QR factorization in R
Base R provides thw qr()
function for QR matrix factorization. The qr()
function returns a QR object with information on the decomposition. When we use qr.Q()
and qr.R()
, it is possible to retrieve the actual factorization matrices.
Given a matrix , the and matrices are returned.
...