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 CenterFile Exchange에서 Matrix Decomposition에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by