public void decompose( SimpleMatrix A ) {

        this.QR = A.copy();

        int N = Math.min(A.numCols(),A.numRows());
        gammas = new double[ A.numCols() ];

        for( int i = 0; i < N; i++ ) {
            // use extract matrix to get the column that is to be zeroed
            SimpleMatrix v = QR.extractMatrix(i, END,i,i+1);
            double max = v.elementMaxAbs();

            if( max > 0 && v.getNumElements() > 1 ) {
                // normalize to reduce overflow issues
                v = v.divide(max);

                // compute the magnitude of the vector
                double tau = v.normF();

                if( v.get(0) < 0 )
                    tau *= -1.0;

                double u_0 = v.get(0) + tau;
                double gamma = u_0/tau;

                v = v.divide(u_0);
                v.set(0,1.0);

                // extract the submatrix of A which is being operated on
                SimpleMatrix A_small = QR.extractMatrix(i,END,i,END);

                // A = (I - &gamma;*u*u<sup>T</sup>)A
                A_small = A_small.plus(-gamma,v.mult(v.transpose()).mult(A_small));

                // save the results
                QR.insertIntoThis(i,i,A_small);
                QR.insertIntoThis(i+1,i,v.extractMatrix(1,END,0,1));

                // Alternatively, the two lines above can be replaced with in-place equations
                // READ THE JAVADOC TO UNDERSTAND HOW THIS WORKS!
//                QR.equation("QR(i:,i:) = A","QR",i,"i",A_small,"A");
//                QR.equation("QR((i+1):,i) = v(1:,0)","QR",i,"i",v,"v");

                // save gamma for recomputing Q later on
                gammas[i] = gamma;
            }
        }
    }
public void decompose ( SimpleMatrix A ) { this . QR = A . copy ( ) ; int N = Math . min ( A . numCols ( ) , A . numRows ( ) ) ; gammas = new double [ A . numCols ( ) ] ; for ( int i = 0 ; i < N ; i ++ ) { SimpleMatrix v = QR . extractMatrix ( i , END , i , i + 1 ) ; double max = v . elementMaxAbs ( ) ; if ( max > 0 && v . getNumElements ( ) > 1 ) { v = v . divide ( max ) ; double tau = v . normF ( ) ; if ( v . get ( 0 ) < 0 ) tau *= - 1.0 ; double u_0 = v . get ( 0 ) + tau ; double gamma = u_0 / tau ; v = v . divide ( u_0 ) ; v . set ( 0 , 1.0 ) ; SimpleMatrix A_small = QR . extractMatrix ( i , END , i , END ) ; A_small = A_small . plus ( - gamma , v . mult ( v . transpose ( ) ) . mult ( A_small ) ) ; QR . insertIntoThis ( i , i , A_small ) ; QR . insertIntoThis ( i + 1 , i , v . extractMatrix ( 1 , END , 0 , 1 ) ) ; gammas [ i ] = gamma ; } } }
Computes the QR decomposition of the provided matrix.

@param A Matrix which is to be decomposed.  Not modified.