QRDecomposition

yields the QR decomposition for a numerical matrix m. The result is a list {q,r}, where q is a unitary matrix and r is an upper‐triangular matrix.
Details and Options

- The original matrix m is equal to ConjugateTranspose[q].r. »
- For non‐square matrices, q is row orthonormal. »
- The matrix r has zeros for all entries below the leading diagonal. »
- With the setting TargetStructure->"Structured", QRDecomposition[m] returns the matrices {q,r} as structured matrices.
- QRDecomposition[m,Pivoting->True] yields a list {q,r,p} where p is a permutation matrix such that m.p is equal to ConjugateTranspose[q].r. »
Examples
open allclose allBasic Examples (3)
Scope (11)
Basic Uses (7)
Find the QR decomposition of a machine-precision matrix:
QR decomposition for a complex matrix:
Use QRDecomposition for an exact matrix:
QR decomposition for an arbitrary-precision matrix:
Use QRDecomposition with a symbolic matrix:
The QR decomposition for a large numerical matrix is computed efficiently:
Special Matrices (4)
Find the QR decomposition for a sparse matrix:
QR decompositions of structured matrices:
Use with a QuantityArray structured matrix that has consistent units:
The matrix is dimensionless; the
matrix gets the units:
QR decomposition of an IdentityMatrix consists of two identity matrices:
QR decomposition of HilbertMatrix:
Options (4)
Pivoting (1)
Compute the QR decomposition using machine arithmetic with pivoting:
The elements along the diagonal of r are in order of decreasing magnitude:
The matrix p is a permutation matrix:
QRDecomposition satisfies m.p==ConjugateTranspose[q].r:
TargetStructure (3)
With TargetStructure->"Dense", the result of QRDecomposition is a list of two dense matrices:
With TargetStructure->"Structured", the result of QRDecomposition is a list containing an OrthogonalMatrix and an UpperTriangularMatrix:
With the settings Pivoting->True and TargetStructure->"Structured", the result of QRDecomposition is a list containing an OrthogonalMatrix, an UpperTriangularMatrix and a PermutationMatrix:
With TargetStructure->"Dense", the result of QRDecomposition is a list of two dense matrices:
With TargetStructure->"Structured", the result of QRDecomposition is a list containing a UnitaryMatrix and an UpperTriangularMatrix:
Applications (8)
Geometry of QRDecomposition (4)
Find an orthonormal basis for the column space of the following matrix , and then use that basis to find a QR factorization of
:
Define as the
column of
and
as the
element of the corresponding Gram–Schmidt basis:
Let be the matrix whose rows are the
:
Let be the matrix whose elements are the components of
along the
basis vector:
This is the same result as given by QRDecomposition:
Compare QR decompositions found using Orthogonalize and QRDecomposition for the following matrix :
Let be the result of applying Orthogonalize to the columns of
:
This is the same result as given by QRDecomposition:
Compare QR decompositions found using Orthogonalize and QRDecomposition for the following matrix :
Let be the result of applying Orthogonalize to the complex-conjugated columns of
:
Up to sign, this is the same result as given by QRDecomposition:
For some applications, it use useful to compute a so-called full QR decomposition, in which the is square (and thus unitary) and
has the same dimensions as the input matrix. Compute the full QR decomposition for the following matrix
:
There are only two linearly independent columns, so and
each have only two rows:
Use NullSpace to find vectors outside the span of the rows of , then orthogonalize the complete set:
Simply pad the matrix with zeros to make it the same shape as
:
Least Squares and Curve Fitting (4)
Use the QR decomposition to find the that minimizes
for the following matrix
and vector
:
Since ,
, and the normal equations
can be recast as
:
As is invertible (because the columns of
are linearly independent), the solution is
:
Confirm the result using LeastSquares:
Use the QR decomposition to solve for the following matrix
and vector
:
Compute the QR decomposition of , which gives an invertible
, as
has linearly independent rows:
Let as if solving the least-squares problem:
As the columns of span
,
must be a solution of the equation:
QRDecomposition can be used to find a best-fit curve to data. Consider the following data:
Extract the and
coordinates from the data:
Let have the columns
and
, so that minimizing
will be fitting to a line
:
As the columns of are linearly independent, the coefficients for a linear least‐squares fit are
:
Verify the coefficients using Fit:
Plot the best-fit curve along with the data:
Find the best-fit parabola to the following data:
Extract the and
coordinates from the data:
Let have the columns
,
and
, so that minimizing
will be fitting to
:
As the columns of are linearly independent, the coefficients for a least‐squares fit are
:
Verify the coefficients using Fit:
Properties & Relations (10)
The rows of q are orthonormal:
m is equal to ConjugateTranspose[q].r:
If is an
matrix, the
matrix will have
columns and the
matrix
columns:
QRDecomposition computes the "thin" decomposition, where and
have MatrixRank[m] rows:
If m is real-valued and invertible, the matrix of its QR decomposition is orthogonal:
If m is invertible, the matrix of its QR decomposition is unitary:
If a is an matrix and MatrixRank[a]==n, the
matrix of its QR decomposition is unitary:
If a is an matrix and MatrixRank[a]==m, the
matrix of its QR decomposition is invertible:
Moreover, PseudoInverse[a]==Inverse[r].q:
Orthogonalize can be used to compute a QR decomposition:
For an approximate matrix, it is typically different from the one found by QRDecomposition:
LeastSquares and QRDecomposition can both be used to solve the least-squares problem:
The Cholesky decomposition of coincides with
's QR decomposition up to phase:
Compute CholeskyDecomposition[ConjugateTranspose[m].]m:
Text
Wolfram Research (1991), QRDecomposition, Wolfram Language function, https://reference.wolfram.com/language/ref/QRDecomposition.html (updated 2024).
CMS
Wolfram Language. 1991. "QRDecomposition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/QRDecomposition.html.
APA
Wolfram Language. (1991). QRDecomposition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/QRDecomposition.html