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.
 
     
   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 all close 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 is dimensionless; the  matrix gets the units:
 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
, and then use that basis to find a QR factorization of  :
:
Define  as the
 as the  column of
 column of  and
 and  as the
 as the  element of the corresponding Gram–Schmidt basis:
 element of the corresponding Gram–Schmidt basis:
Let  be the matrix whose rows are the
 be the matrix whose rows are the  :
:
Let  be the matrix whose elements are the components of
 be the matrix whose elements are the components of  along the
 along the  basis vector:
 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
 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
 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
 is square (and thus unitary) and  has the same dimensions as the input matrix. Compute the full QR decomposition for the following matrix
 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
 and  each have only two rows:
 each have only two rows:
Use NullSpace to find vectors outside the span of the rows of  , then orthogonalize the complete set:
, then orthogonalize the complete set:
Simply pad the  matrix with zeros to make it the same shape as
 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
 that minimizes ![TemplateBox[{{{m, ., x}, -, b}}, Norm] TemplateBox[{{{m, ., x}, -, b}}, Norm]](Files/QRDecomposition.en/44.png) for the following matrix
 for the following matrix  and vector
 and vector  :
:
Since ![m=TemplateBox[{q}, Transpose].r m=TemplateBox[{q}, Transpose].r](Files/QRDecomposition.en/48.png) ,
, ![TemplateBox[{m}, Transpose].m=TemplateBox[{r}, Transpose].r TemplateBox[{m}, Transpose].m=TemplateBox[{r}, Transpose].r](Files/QRDecomposition.en/49.png) , and the normal equations
, and the normal equations ![TemplateBox[{m}, Transpose].m.x=TemplateBox[{m}, Transpose].b TemplateBox[{m}, Transpose].m.x=TemplateBox[{m}, Transpose].b](Files/QRDecomposition.en/50.png) can be recast as
 can be recast as ![TemplateBox[{r}, Transpose].r.x=TemplateBox[{r}, Transpose].q.b TemplateBox[{r}, Transpose].r.x=TemplateBox[{r}, Transpose].q.b](Files/QRDecomposition.en/51.png) :
:
As  is invertible (because the columns of
 is invertible (because the columns of  are linearly independent), the solution is
 are linearly independent), the solution is ![x=TemplateBox[{r}, Inverse].q.b x=TemplateBox[{r}, Inverse].q.b](Files/QRDecomposition.en/54.png) :
:
Confirm the result using LeastSquares:
Use the QR decomposition to solve  for the following matrix
 for the following matrix  and vector
 and vector  :
:
Compute the QR decomposition of ![TemplateBox[{m}, Transpose] TemplateBox[{m}, Transpose]](Files/QRDecomposition.en/58.png) , which gives an invertible
, which gives an invertible  , as
, as  has linearly independent rows:
 has linearly independent rows:
Let ![x=TemplateBox[{q}, Transpose].TemplateBox[{{(, TemplateBox[{r}, Transpose, SyntaxForm -> SuperscriptBox], )}}, Inverse].b x=TemplateBox[{q}, Transpose].TemplateBox[{{(, TemplateBox[{r}, Transpose, SyntaxForm -> SuperscriptBox], )}}, Inverse].b](Files/QRDecomposition.en/61.png) as if solving the least-squares problem:
 as if solving the least-squares problem:
As the columns of  span
 span ![TemplateBox[{}, Reals]^3 TemplateBox[{}, Reals]^3](Files/QRDecomposition.en/63.png) ,
,  must be a solution of the equation:
 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
 and  coordinates from the data:
 coordinates from the data:
Let  have the columns
 have the columns  and
 and  , so that minimizing
, so that minimizing ![TemplateBox[{{{m, ., {{, {a, ,, b}, }}}, -, y}}, Norm] TemplateBox[{{{m, ., {{, {a, ,, b}, }}}, -, y}}, Norm]](Files/QRDecomposition.en/70.png) will be fitting to a line
 will be fitting to a line  :
:
As the columns of  are linearly independent, the coefficients for a linear least‐squares fit are
 are linearly independent, the coefficients for a linear least‐squares fit are ![TemplateBox[{r}, Inverse].q.y TemplateBox[{r}, Inverse].q.y](Files/QRDecomposition.en/73.png) :
:
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
 and  coordinates from the data:
 coordinates from the data:
Let  have the columns
 have the columns  ,
,  and
 and  , so that minimizing
, so that minimizing ![TemplateBox[{{{m, ., {{, {a, ,, b, ,, c}, }}}, -, y}}, Norm] TemplateBox[{{{m, ., {{, {a, ,, b, ,, c}, }}}, -, y}}, Norm]](Files/QRDecomposition.en/80.png) will be fitting to
 will be fitting to  :
:
As the columns of  are linearly independent, the coefficients for a least‐squares fit are
 are linearly independent, the coefficients for a least‐squares fit are ![TemplateBox[{r}, Inverse].q.y TemplateBox[{r}, Inverse].q.y](Files/QRDecomposition.en/83.png) :
:
Verify the coefficients using Fit:
Properties & Relations (10)
The rows of q are orthonormal:
m is equal to ConjugateTranspose[q].r:
If  is an
 is an  matrix, the
 matrix, the  matrix will have
 matrix will have  columns and the
 columns and the  matrix
 matrix  columns:
 columns:
QRDecomposition computes the "thin" decomposition, where  and
 and  have MatrixRank[m] rows:
 have MatrixRank[m] rows:
If m is real-valued and invertible, the  matrix of its QR decomposition is orthogonal:
 matrix of its QR decomposition is orthogonal:
If m is invertible, the  matrix of its QR decomposition is unitary:
 matrix of its QR decomposition is unitary:
If a is an  matrix and MatrixRank[a]==n, the
 matrix and MatrixRank[a]==n, the  matrix of its QR decomposition is unitary:
 matrix of its QR decomposition is unitary:
If a is an  matrix and MatrixRank[a]==m, the
 matrix and MatrixRank[a]==m, the  matrix of its QR decomposition is invertible:
 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 ![TemplateBox[{m}, ConjugateTranspose].m TemplateBox[{m}, ConjugateTranspose].m](Files/QRDecomposition.en/98.png) coincides with
 coincides with  's QR decomposition up to phase:
's QR decomposition up to phase:
Compute CholeskyDecomposition[ConjugateTranspose[m].]m:
Related Guides
History
Introduced in 1991 (2.0) | Updated in 2024 (14.0)
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
BibTeX
@misc{reference.wolfram_2025_qrdecomposition, author="Wolfram Research", title="{QRDecomposition}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/QRDecomposition.html}", note=[Accessed: 30-October-2025]}
BibLaTeX
@online{reference.wolfram_2025_qrdecomposition, organization={Wolfram Research}, title={QRDecomposition}, year={2024}, url={https://reference.wolfram.com/language/ref/QRDecomposition.html}, note=[Accessed: 30-October-2025]}


![m=TemplateBox[{q}, ConjugateTranspose].r m=TemplateBox[{q}, ConjugateTranspose].r](Files/QRDecomposition.en/4.png)
![TemplateBox[{q}, Transpose].r TemplateBox[{q}, Transpose].r](Files/QRDecomposition.en/5.png)
![TemplateBox[{q}, Transpose].r TemplateBox[{q}, Transpose].r](Files/QRDecomposition.en/6.png)











