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
qbar = A(:,i);
R2(:,i) = Q2'*qbar
qbar = qbar - Q2*R2(:,i);
R2(i,i) = norm(qbar);
Q2(:,i) = qbar/R2(i,i);
end
1 Comment
Jan (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/83798-sign-differences-in-qr-decomposition#comment_162632
Sign in to comment.