public Matrix getQMatrix() {
        Matrix qMatrix = new Matrix(m,n);
        double[][] Q  = qMatrix.getArray();
        for (int k = n-1; k >= 0; k--) {
            for (int i = 0; i < m; i++) {
                Q[i][k] = 0.0;
            }
            Q[k][k] = 1.0;
            for (int j = k; j < n; j++) {
                if (QR[k][k] != 0.0) {
                    double x = 0.0;
                    for (int i = k; i < m; i++) {
                        x += QR[i][k]*Q[i][j];
                    }
                    x = -x/QR[k][k];
                    for (int i = k; i < m; i++) {
                        Q[i][j] += x*QR[i][k];
                    }
                }
            }
        }
        for (int i = 0; i < qMatrix.getRowDimension(); i++) {
            for (int j = 0; j < qMatrix.getColumnDimension(); j++) {
                if (Q[i][j] != 0.0) {
                    Q[i][j] = -Q[i][j];
                }
            }
        }
        qMatrix = new Matrix(Q);
        qVals = qMatrix.getArrayCopy();
        return qMatrix;
    }