QRDecomposition
✖
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)Summary of the most common use cases
The decomposition of a 2×2 matrix into a unitary (orthogonal) matrix and upper triangular matrix
:

https://wolfram.com/xid/09cmhdv2a-f0rg9h


https://wolfram.com/xid/09cmhdv2a-m32d4c

Compute the QR decomposition for a 3×2 matrix with exact values:

https://wolfram.com/xid/09cmhdv2a-9lje0


https://wolfram.com/xid/09cmhdv2a-cv0l6s

Compute the QR decomposition for a 2×3 matrix with approximate numerical values:

https://wolfram.com/xid/09cmhdv2a-dpl43b


https://wolfram.com/xid/09cmhdv2a-nei5vj

Scope (11)Survey of the scope of standard use cases
Basic Uses (7)
Find the QR decomposition of a machine-precision matrix:

https://wolfram.com/xid/09cmhdv2a-s95rjo


https://wolfram.com/xid/09cmhdv2a-naene4

QR decomposition for a complex matrix:

https://wolfram.com/xid/09cmhdv2a-pnbobq

Use QRDecomposition for an exact matrix:

https://wolfram.com/xid/09cmhdv2a-id7895

QR decomposition for an arbitrary-precision matrix:

https://wolfram.com/xid/09cmhdv2a-jdo4f1

Use QRDecomposition with a symbolic matrix:

https://wolfram.com/xid/09cmhdv2a-rggp6

The QR decomposition for a large numerical matrix is computed efficiently:

https://wolfram.com/xid/09cmhdv2a-bjhh1d

https://wolfram.com/xid/09cmhdv2a-n2hz99

QR decomposition of a non-square matrix:

https://wolfram.com/xid/09cmhdv2a-f1mxzj

Special Matrices (4)
Find the QR decomposition for a sparse matrix:

https://wolfram.com/xid/09cmhdv2a-kfksuk


https://wolfram.com/xid/09cmhdv2a-qvlhy


https://wolfram.com/xid/09cmhdv2a-tr53kr


https://wolfram.com/xid/09cmhdv2a-gyqjms

QR decompositions of structured matrices:

https://wolfram.com/xid/09cmhdv2a-fyaetx


https://wolfram.com/xid/09cmhdv2a-c0k3bb

Use with a QuantityArray structured matrix that has consistent units:

https://wolfram.com/xid/09cmhdv2a-d2yyup

The matrix is dimensionless; the
matrix gets the units:

https://wolfram.com/xid/09cmhdv2a-ntiy7m

QR decomposition of an IdentityMatrix consists of two identity matrices:

https://wolfram.com/xid/09cmhdv2a-hkjl2l


https://wolfram.com/xid/09cmhdv2a-fpcymb

QR decomposition of HilbertMatrix:

https://wolfram.com/xid/09cmhdv2a-df3260

Options (4)Common values & functionality for each option
Pivoting (1)

https://wolfram.com/xid/09cmhdv2a-lh6mxs
Compute the QR decomposition using machine arithmetic with pivoting:

https://wolfram.com/xid/09cmhdv2a-dgm7ef

The elements along the diagonal of r are in order of decreasing magnitude:

https://wolfram.com/xid/09cmhdv2a-dnlryx

The matrix p is a permutation matrix:

https://wolfram.com/xid/09cmhdv2a-fj1u0c

QRDecomposition satisfies m.p==ConjugateTranspose[q].r:

https://wolfram.com/xid/09cmhdv2a-h6puao

TargetStructure (3)

https://wolfram.com/xid/09cmhdv2a-dnstlz

With TargetStructure->"Dense", the result of QRDecomposition is a list of two dense matrices:

https://wolfram.com/xid/09cmhdv2a-hqa43p

With TargetStructure->"Structured", the result of QRDecomposition is a list containing an OrthogonalMatrix and an UpperTriangularMatrix:

https://wolfram.com/xid/09cmhdv2a-my3g3t


https://wolfram.com/xid/09cmhdv2a-fqin7i

With the settings Pivoting->True and TargetStructure->"Structured", the result of QRDecomposition is a list containing an OrthogonalMatrix, an UpperTriangularMatrix and a PermutationMatrix:

https://wolfram.com/xid/09cmhdv2a-bs7v4o


https://wolfram.com/xid/09cmhdv2a-fy103d

With TargetStructure->"Dense", the result of QRDecomposition is a list of two dense matrices:

https://wolfram.com/xid/09cmhdv2a-inajm4

With TargetStructure->"Structured", the result of QRDecomposition is a list containing a UnitaryMatrix and an UpperTriangularMatrix:

https://wolfram.com/xid/09cmhdv2a-1hbhy

Applications (8)Sample problems that can be solved with this function
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
:

https://wolfram.com/xid/09cmhdv2a-pnviy4

https://wolfram.com/xid/09cmhdv2a-gy514n

Define as the
column of
and
as the
element of the corresponding Gram–Schmidt basis:

https://wolfram.com/xid/09cmhdv2a-bqnxxw

https://wolfram.com/xid/09cmhdv2a-ltwu9n

Let be the matrix whose rows are the
:

https://wolfram.com/xid/09cmhdv2a-kqdtk5
Let be the matrix whose elements are the components of
along the
basis vector:

https://wolfram.com/xid/09cmhdv2a-jfrefj


https://wolfram.com/xid/09cmhdv2a-nem31

This is the same result as given by QRDecomposition:

https://wolfram.com/xid/09cmhdv2a-1mmu3b

Compare QR decompositions found using Orthogonalize and QRDecomposition for the following matrix :

https://wolfram.com/xid/09cmhdv2a-braheb
Let be the result of applying Orthogonalize to the columns of
:

https://wolfram.com/xid/09cmhdv2a-w5buha


https://wolfram.com/xid/09cmhdv2a-tk6hq0


https://wolfram.com/xid/09cmhdv2a-kz848o

This is the same result as given by QRDecomposition:

https://wolfram.com/xid/09cmhdv2a-i37kkp

Compare QR decompositions found using Orthogonalize and QRDecomposition for the following matrix :

https://wolfram.com/xid/09cmhdv2a-drhyqx
Let be the result of applying Orthogonalize to the complex-conjugated columns of
:

https://wolfram.com/xid/09cmhdv2a-qol4bl


https://wolfram.com/xid/09cmhdv2a-f1a1i4


https://wolfram.com/xid/09cmhdv2a-y398nl

Up to sign, this is the same result as given by QRDecomposition:

https://wolfram.com/xid/09cmhdv2a-iwme4r

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
:

https://wolfram.com/xid/09cmhdv2a-xx1hbt
There are only two linearly independent columns, so and
each have only two rows:

https://wolfram.com/xid/09cmhdv2a-wx04m4

Use NullSpace to find vectors outside the span of the rows of , then orthogonalize the complete set:

https://wolfram.com/xid/09cmhdv2a-zxmphd


https://wolfram.com/xid/09cmhdv2a-7at960

Simply pad the matrix with zeros to make it the same shape as
:

https://wolfram.com/xid/09cmhdv2a-yd0k3h

Verify that this is also a valid QR decomposition:

https://wolfram.com/xid/09cmhdv2a-431lo

Least Squares and Curve Fitting (4)
Use the QR decomposition to find the that minimizes
for the following matrix
and vector
:

https://wolfram.com/xid/09cmhdv2a-thcei2

https://wolfram.com/xid/09cmhdv2a-ucwc8w

Since ,
, and the normal equations
can be recast as
:

https://wolfram.com/xid/09cmhdv2a-cxdb6j

As is invertible (because the columns of
are linearly independent), the solution is
:

https://wolfram.com/xid/09cmhdv2a-qtw22b

Confirm the result using LeastSquares:

https://wolfram.com/xid/09cmhdv2a-dl4g46

Use the QR decomposition to solve for the following matrix
and vector
:

https://wolfram.com/xid/09cmhdv2a-cga6ui
Compute the QR decomposition of , which gives an invertible
, as
has linearly independent rows:

https://wolfram.com/xid/09cmhdv2a-s0ynf

Let as if solving the least-squares problem:

https://wolfram.com/xid/09cmhdv2a-ch536g

As the columns of span
,
must be a solution of the equation:

https://wolfram.com/xid/09cmhdv2a-b8jfll


https://wolfram.com/xid/09cmhdv2a-4qbaw4
QRDecomposition can be used to find a best-fit curve to data. Consider the following data:

https://wolfram.com/xid/09cmhdv2a-v42zji

Extract the and
coordinates from the data:

https://wolfram.com/xid/09cmhdv2a-i4v6jo
Let have the columns
and
, so that minimizing
will be fitting to a line
:

https://wolfram.com/xid/09cmhdv2a-pkve26
As the columns of are linearly independent, the coefficients for a linear least‐squares fit are
:

https://wolfram.com/xid/09cmhdv2a-7p26fs

Verify the coefficients using Fit:

https://wolfram.com/xid/09cmhdv2a-480xbe

Plot the best-fit curve along with the data:

https://wolfram.com/xid/09cmhdv2a-wzqna8

Find the best-fit parabola to the following data:

https://wolfram.com/xid/09cmhdv2a-x7pawr

Extract the and
coordinates from the data:

https://wolfram.com/xid/09cmhdv2a-w5dwto
Let have the columns
,
and
, so that minimizing
will be fitting to
:

https://wolfram.com/xid/09cmhdv2a-bmqc8e
As the columns of are linearly independent, the coefficients for a least‐squares fit are
:

https://wolfram.com/xid/09cmhdv2a-z5bw8q

Verify the coefficients using Fit:

https://wolfram.com/xid/09cmhdv2a-pp5xfy

Plot the best-fit curve along with the data:

https://wolfram.com/xid/09cmhdv2a-04d0qo

Properties & Relations (10)Properties of the function, and connections to other functions

https://wolfram.com/xid/09cmhdv2a-9ayis

https://wolfram.com/xid/09cmhdv2a-gnqq2
The rows of q are orthonormal:

https://wolfram.com/xid/09cmhdv2a-l05cob


https://wolfram.com/xid/09cmhdv2a-jark6o

m is equal to ConjugateTranspose[q].r:

https://wolfram.com/xid/09cmhdv2a-blzh6

If is an
matrix, the
matrix will have
columns and the
matrix
columns:

https://wolfram.com/xid/09cmhdv2a-zz00u9

QRDecomposition computes the "thin" decomposition, where and
have MatrixRank[m] rows:

https://wolfram.com/xid/09cmhdv2a-33wdt8

If m is real-valued and invertible, the matrix of its QR decomposition is orthogonal:

https://wolfram.com/xid/09cmhdv2a-pmxsqt


https://wolfram.com/xid/09cmhdv2a-5sa5i1

If m is invertible, the matrix of its QR decomposition is unitary:

https://wolfram.com/xid/09cmhdv2a-wtfuiu


https://wolfram.com/xid/09cmhdv2a-5gj419

If a is an matrix and MatrixRank[a]==n, the
matrix of its QR decomposition is unitary:

https://wolfram.com/xid/09cmhdv2a-ya23ej


https://wolfram.com/xid/09cmhdv2a-lj70m8

If a is an matrix and MatrixRank[a]==m, the
matrix of its QR decomposition is invertible:

https://wolfram.com/xid/09cmhdv2a-mp05tq


https://wolfram.com/xid/09cmhdv2a-4vkop3

Moreover, PseudoInverse[a]==Inverse[r].q:

https://wolfram.com/xid/09cmhdv2a-6ckkvb

Orthogonalize can be used to compute a QR decomposition:

https://wolfram.com/xid/09cmhdv2a-r62vn2

For an approximate matrix, it is typically different from the one found by QRDecomposition:

https://wolfram.com/xid/09cmhdv2a-88rusm

LeastSquares and QRDecomposition can both be used to solve the least-squares problem:

https://wolfram.com/xid/09cmhdv2a-h3z3e9

https://wolfram.com/xid/09cmhdv2a-e5dgz8

The Cholesky decomposition of coincides with
's QR decomposition up to phase:

https://wolfram.com/xid/09cmhdv2a-y8d31v
Compute CholeskyDecomposition[ConjugateTranspose[m].]m:

https://wolfram.com/xid/09cmhdv2a-nk43sc
Find the QR decomposition of :

https://wolfram.com/xid/09cmhdv2a-bpxj4b
is the same as
except for the choice of phase for each row:

https://wolfram.com/xid/09cmhdv2a-vs9p8n

Wolfram Research (1991), QRDecomposition, Wolfram Language function, https://reference.wolfram.com/language/ref/QRDecomposition.html (updated 2024).
Text
Wolfram Research (1991), QRDecomposition, Wolfram Language function, https://reference.wolfram.com/language/ref/QRDecomposition.html (updated 2024).
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.
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
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: 24-March-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: 24-March-2025
]}