code: public SimpleMatrix getQ() {
          SimpleMatrix Q = SimpleMatrix.identity(QR.numRows());
  
          int N = Math.min(QR.numCols(),QR.numRows());
  
          // compute Q by first extracting the householder vectors from the columns of QR and then applying it to Q
          for( int j = N-1; j>= 0; j-- ) {
              SimpleMatrix u = new SimpleMatrix(QR.numRows(),1);
              u.insertIntoThis(j,0,QR.extractMatrix(j, END,j,j+1));
              u.set(j,1.0);
  
              // A = (I - &gamma;*u*u<sup>T</sup>)*A<br>
              Q = Q.plus(-gammas[j],u.mult(u.transpose()).mult(Q));
          }
  
          return Q;
      }
docs: Returns the Q matrix.