qrQR decomposition
Let
In the above equation,
The error in
where the permuted matrix A is complex).
The matrix
for all
Suppose that
Note that
The error in
The matrix
for all
R = qr(A)R = qr(A, 0)R = qr(A, 'vector')R = qr(A, 'matrix')A is an R such that triu(R).[Q,R] = qr(A)[Q,Rp,P] = qr(A)[Q,Rp,e] = qr(A, 'vector')[Q,Rp,P] = qr(A, 'matrix')[Q1,R1] = qr(A, 0)[Q1,Rp1,e] = qr(A, 0)A is an | Output arguments | Variables in the equations | Sizes | Meaning |
|---|---|---|---|
Q | |||
Q1 if | Thin | ||
Q1 if | |||
R | |||
Rp | Permuted | ||
R1 if | Thin | ||
R1 if | |||
Rp1 if | Permuted thin | ||
Rp1 if | Permuted | ||
P | Permutation matrix | ||
e | Permutation vector |
R.A = rand(3,5);
[Q,R] = qr(A);
% m < n. Therefore, R has the form [R2 R3]
% where R2 is upper triangular
R
% Q*R and A are the same
% (ignoring rounding errors)
Q*R-A
B = rand(5,3);
[Q,R] = qr(B);
% m > n. Therefore, R has the form [R1;0]
% where R1 is upper triangular
R
% Q*R and B are the same
% (ignoring rounding errors)
Q*R-B
R =
-1.2683 -0.2718 -0.7296 -0.4461 -0.9179
0.0000 -0.7927 -0.0660 0.0097 -0.6946
0.0000 0.0000 0.4922 0.3550 0.2499
ans = 1e-16 ×
0.0000 0.1388 0.5551 0.5551 2.7756
-0.2776 0.0000 -0.2776 0.1388 0.0000
0.0000 -0.1388 0.0000 0.0000 2.2204
R =
-1.4719 -0.5101 -1.2602
0.0000 -0.2651 -0.6190
0.0000 0.0000 -0.3916
0.0000 0.0000 0.0000
0.0000 0.0000 0.0000
ans = 1e-16 ×
0.0000 0.0000 2.7756
-1.1102 0.0000 -1.1102
0.0000 0.0000 1.1102
0.0000 0.5551 -1.1102
0.0000 0.5551 1.1102
A = rand(5,3);
[Q,R] = qr(A);
% R has the form [R1;0]
% where R1 is upper triangular
R
% With the second input argument being 0,
% qr() returns the upper triangular matrix
% without giving the zero matrix
[Q,R1] = qr(A,0);
R1
R =
-1.5226 -0.4083 -0.8611
0.0000 0.7716 0.7349
0.0000 0.0000 -0.4714
0.0000 0.0000 0.0000
0.0000 0.0000 0.0000
R1 =
-1.5226 -0.4083 -0.8611
0.0000 0.7716 0.7349
0.0000 0.0000 -0.4714
A = rand(3,5);
[Q,R,P] = qr(A,'matrix');
% A*E and Q*R are the same
% (ignoring rounding errors)
A*P-Q*R
ans = 1e-16 ×
1.1102 1.1102 0.8327 0.5551 0.0000
0.0000 1.1102 0.9714 0.0000 0.6939
0.0000 3.3307 0.5551 -0.1388 0.0000
e.% Randomly generated matrix.
a = randi(10,4,5);
% Vector e contains permutation information.
[Q,R,e] = qr(a,'vector');
% Construct a permuation matrix P using e.
P = zeros(size(a,2));
for r = 1:size(a,2)
P(e(r),r) = 1;
end
% Permutation matrix P2 given by qr()
% with second input argument being 'matrix'
[Q,R,P2] = qr(a,'matrix');
% Permutation matrices P and P2 are the same.
P
P2
P =
0.0000 0.0000 0.0000 1.0000 0.0000
0.0000 1.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 1.0000
1.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 1.0000 0.0000 0.0000
P2 =
0.0000 0.0000 0.0000 1.0000 0.0000
0.0000 1.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 1.0000
1.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 1.0000 0.0000 0.0000