Sign differences in QR decomposition

28 ビュー (過去 30 日間)
Travis Kocian
Travis Kocian 2013 年 8 月 1 日
I am trying to use a simple QR decomposition and compare the results to that of the qr matlab function. I generate a random A matrix and then compare the Q and R values separately. For some reason, although the magnitudes of each element is the same there is sometimes a difference in sign between some of the terms. This is fine in the fact that Q*R = A in both cases, however I need to use R*Q. Any help on what is happening/how to fix it?
m = 4;
casenum = randi(3,1)
if casenum == 1
A = randn(m)
end
if casenum == 2
A = i*randn(m)
end
if casenum == 3
pownum = randi(2,m);
A = randn(m) + randn(m).*(i.^pownum)
end
[Q1,R1] = qr(A);
Q2 = zeros(m,m);
R2 = zeros(m,m);
for i=1:m
% Grab the next column of A.
qbar = A(:,i);
% Compute the current vector projection onto the previous columns of Q
R2(:,i) = Q2'*qbar
% Subtract out the projections so qbar is orthogonal
qbar = qbar - Q2*R2(:,i);
% Normalize qbar and append it to Q
R2(i,i) = norm(qbar);
Q2(:,i) = qbar/R2(i,i);
end
  1 件のコメント
Jan
Jan 2013 年 8 月 2 日
When Q*R=A is correct in both cases, both cases are correct results. This means unequivocally, that there is no "sign error" and I have deleted the corresponding tag. As Richard has explained already, the QR-decomposition is not unique. So you observe the expected effects.

サインインしてコメントする。

採用された回答

Richard Brown
Richard Brown 2013 年 8 月 1 日
It's only unique up to the signs of the rows of R. If you want to enforce positive diagonals of R, and thereby get a unique factorisation, construct
D = diag(sign(diag(R)));
and then
Qunique = Q*D; Runique = D*R;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Decomposition についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by