0
votes

I use C++ 14 and Eigen. For n x n matrix A how can I extract Q and R matrices using QR decomposition in Eigen, I tried to read the documentation but I'm disorientated

I've obtain only R:

    HouseholderQR<MatrixXd> qr(A);
    qr.compute(A);
    MatrixXd R = qr.matrixQR().template triangularView<Upper>();

Anyway, I just want to convert matrix A into a triangular matrix (in a efficient way, around O(n^3) I think), which have the determinant equal to determinant of A, in this way accept any other methods to do this in Eigen. (or another Linear Algebra library, if you know some good libraries I waiting for suggestions )

1
What about this function: eigen.tuxfamily.org/dox/… ? It returns Q and can be assigned to a matrix. - RL-S
What's wrong with using (one of) the LU decomposition(s)? They even directly provide a .determinant() method. - chtz

1 Answers

0
votes

You can get Q and R as follows:

Eigen::MatrixXd Q = qr.householderQ();
Eigen::MatrixXd QR = qr.matrixQR();

The R matrix is in the upper triangular portion of matrix QR. You can compute the determinant of R as R.diagonal().prod() which is equal in magnitude to A.determinant(). If you want to isolate the upper triangular portion you can do this:

Eigen::MatrixXd T = R.triangularView<Eigen::UnitUpper>();