MATLAB: QR decomposition – Why is the first element of an orthogonal matrix always negative

MATLABqr decomposition

Hi, I noticed that the first element of an orthogonal matrix extracted from the qr() function is always negative, whatever the initial matrix and its size. The other elements do not have fixed signs though.
In the simple code below, j=0 always.
for i=1:1:100000
[Q,~] = qr(randn(3,3));
if Q(1,1)>=0
Why is that so ?

Best Answer

  • It is entirely arbitrary. If
    Q*R = A
    then it is equally true that
    (-Q)*(-R) = A
    Q is just a set of orthogonal vectors. They could have arbitrarily switched the signs on each vector in Q, which would have impacted R of course, but not in any meaningful way. And there is no constraint on the signs of the diagonal elements of R either. So it appears to have simply been an arbitrary choice made.