Calculates the QR decomposition of a matrix.
(q, r) = QR(a, mode)
(q, r, p) = QR(a, mode)
a |
- |
A square or rectangular matrix. |
||||
mode |
- |
Optional. An integer, the form of the output matrices:
|
QR(a, mode)
a |
- |
A square or rectangular matrix. |
||||||
mode |
- |
Optional. An integer, the type of matrix to return:
|
(q, r) = QR(a, mode) returns separate q and r components such that
(q, r, p) = QR(a, mode) returns separate q and r components and a permutation matrix p such that
QR(a, mode) returns a single component or the combined upper and orthogonal matrix.
A = {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
(q, r) = qr(A)
q == {{-0.267261, 0.872872, 0.408248},
{-0.534522, 0.218218, -0.816497},
{-0.801784, -0.436436, 0.408248}}
r == {{-3.741657, -8.552360, -13.363062},
{ 0.000000, 1.963961, 3.927922},
{ 0.000000, 0.000000, 0.000000}}
q' *^ q == q *^ q' == {{1, 0, 0},
{0, 1, 0},
{0, 0, 1}}
q *^ r == {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
The input matrix A is decomposed into a orthogonal matrix q and an upper triangular matrix r such that
A = {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
(qq, rr, p) = qr(A)
qq == {{-0.502571, 0.762073, 0.408248},
{-0.574367, 0.058621, -0.816497},
{-0.646162, -0.644831, 0.408248}}
rr == {{-13.9284, -3.58979, -8.75909},
{ 0, -1.05518, -0.527589},
{ 0, 0, 1.11022e-015}}
p == {{0, 1, 0},
{0, 0, 1},
{1, 0, 0}}
qq *^ rr == {{7, 1, 4},
{8, 2, 5},
{9, 3, 6}}
A *^ p == {{7, 1, 4},
{8, 2, 5},
{9, 3, 6}}
For this case, qq is a unitary matrix, rr is an upper triangular matrix with diagonal elements of decreasing magnitude and p is the permutation matrix such that:
qq *^ rr == a *^ p
A = {{1, 2, 3},
{4, 5, 6},
{7, 8, 10}}
b = {14, 32, 53}
(q, r) = qr(A)
v = q' *^ b
w = r \^ v
x = A \^ b
w == x == {1, 2, 3}
A *^ w == A *^ x == {14, 32, 53}
Using QR decomposition, the solution x to
W1: {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
W2: qr(W1, 01)
{{-3.74, -8.55, -13.36},
{ 0.00, 1.96, 3.93},
{ 0.00, 0.00, 0.00}}
W3: qr(W1, 10)
{{-0.27, 0.87, 0.41},
{-0.53, 0.22, -0.82},
{-0.80, -0.44, 0.41}}
W4: W3 *^ W2
{{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
The input matrix A is decomposed into an orthogonal matrix q and an upper triangle matrix r such that
For a non-square MxN matrix where M > N
(q, r) = qr(A, 0)
returns the components in compact form where q is size MxN and r is size NxN. If
For an over determined or under determined system of equations of the form
A \^ b
returns the best solution for x in the least squares sense.
See LINFIT to fit linear combination of arbitrary basis functions to a series using the method of least squares with QR decomposition.
See DADiSP/MatrixXL to significantly optimize QR.