Sign differences in QR decomposition

24 次查看(过去 30 天)
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 中查找有关 Measurements and Testbenches 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by