public Matrix getRMatrix() {
        Matrix rMatrix = new Matrix(n,n);
        double[][] R = rMatrix.getArray();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i < j) {
                    R[i][j] = -QR[i][j];
                } else if (i > j) {
                    R[i][j] = 0.0;
                } else { // i == j
                    R[i][j] = -diagR[i];
                }
            }
        }
        rMatrix = new Matrix(R);
        rVals = rMatrix.getArray();
        return rMatrix;
    }