public qr_fact_househ(Matrix M) {
        // Declare global variables
        QR = M.getArrayCopy();
        m = M.getRowDimension();
        n = M.getColumnDimension();
        if (!(m >= n)) {
            entryError();
        }
        diagR = new double[n];

        // Outer loop
        for (int k = 0; k < n; k++) {
            //Compute 2-norm of outer loop
            double norm = 0;
            for (int i = k; i < m; i++) {
                norm = Math.hypot(norm, QR[i][k]);
            }

            if (norm != 0.0) {
                // Form k-th household vector
                if (QR[k][k] < 0) {
                    norm = -norm;
                }
                for (int i = k; i < m; i++) {
                    QR[i][k] /= norm;
                }
                QR[k][k] += 1.0;

                for (int j = k+1; j < n; j++) {
                    double x = 0.0;
                    for (int i = k; i < m; i++) {
                        x += QR[i][k]*QR[i][j];
                    }
                    x = -x/QR[k][k];
                    for (int i = k; i < m; i++) {
                        QR[i][j] += x*QR[i][k];
                    }
                }
            }
            diagR[k] = -norm;
        }

    }