title: Matlab QR householder factorization incorrect output
body: <p>I'm trying to write a program that gets an mxn matrix and QR decomposes it.</p>
  
  <p>It's not finished yet, but I've encountered a problem.
  I've tried running my program with the example shown at wikipedia <a href="http://en.wikipedia.org/wiki/QR_decomposition" rel="nofollow">http://en.wikipedia.org/wiki/QR_decomposition</a> </p>
  
  <pre><code>A=[12,-51,4;6,167,-68;-4,24,-41]
  </code></pre>
  
  <p>What they called Q1, Q2...I called Qtemp. and everytime i calculate Qtemp, i print it in order to see that I get same result as wikipedia. For Q1 I do, but for Q2 I don't.</p>
  
  <p>Their Q2 and mine are of the same value, but different signs. where they have a + i have a -, where they have a -, i have a +.</p>
  
  <p>this is my code:</p>
  
  <pre><code>    Q=eye(m);
  R=A;
  for i=1:min(m-1,n)
      ei=zeros(n,1);
      ei(i,1)=1;
      x=A(:,i);
      for j=1:i-1
          x(j,1)=0;
      end
      u=x-norm(x)*ei;
      v=u/norm(u);
      Qtemp=eye(m)-2*(v*v');
      A=Qtemp*A;
      disp(Qtemp);
  end
  </code></pre>
  
  <p>I literally just copied their algorithm and translated it to code, but still bad output for second Qtemp.</p>