BenBenBen
Registered Member

Hello,
First of all, thank you for the amazing work you've done with eigen. This library is a pleasure to use, with a great API. However, I'm a bit confused by the documentation of HouseHolderQR, and haven't found a solution in this forum. I'm looking to get the Q and R matrix of a QR decomposition of a matrix using HouseHolderQR. The documentation indicates that the method matrixQR() yields "a reference to the matrix where the Householder QR decomposition is stored in a LAPACKcompatible way." What is the easiest way to get Q and R ? Is there a way to get these matrices using eigen, or do I have to look at the way lapack stores this matrix and retrieve it "by hand" ? If this is the case, should this function be added to the existing implementation ? It would prevent errors related to rowwise vs columnwise storage, etc... I do need Q and R because I'm dealing with an algorithm that uses these matrices as a basis for other things, so my goal is not simply to solve a linear system. Thank you for the help, and congratulation for your work ! I'm really looking forward eigen 3.1 with MKL integration. Benoit 
BenBenBen
Registered Member

I am replying to myself, because the answer might be of some use for other people.
By looking at the implementation of HouseHolderQR, there is a member function householderQ() that does not have any comments even though it is public. I believe this is the reason why it doesn't appear in the documentation http://eigen.tuxfamily.org/dox/classEigen_1_1HouseholderQR.html. So, to get the Q Matrix, one just has to convert m.householderQ() into a MatrixXd for instance, and then the R matrix is the upper triangular matrix of matrixQR(). Should these indications be added to the documentation ? Shouldn't householderQ() be documented ? 
jitseniesen
Registered Member

Yes, to both question. It seems that the documentation of the HouseHolderQR class can be greatly improved. A patch would be very welcome.

subhadeepk
Registered Member

How to get the permutation matrix? On doing the QR decompostion of matrix X, I can get the Q and R matrix but I require the P matrix also.How to get it?

ggael
Moderator

I guess you are referring to the columnpivoting QR variant available through the ColPivHouseholderQR class: http://eigen.tuxfamily.org/dox/classEig ... derQR.html. As you can see in the doc, there is a colsPermutation() method to get "P".

subhadeepk
Registered Member

I found the solution, so I am reporting (Might help somebody like me ) . qr.compute(A); MatrixXd P = qr.colsPermutation(); 
Registered users: Baidu [Spider], bartoloni, Bing [Bot], boudewijn, Exabot [Bot], firewalker, gmassimiani, Google [Bot], kdedeshmukh, Majestic12 [Bot], maudhit, mesoptafel, odysseusart, ratheranonymous, Sogou [Bot], TheraHedwig, tosky, waynes, wolfi323, YaCy [Bot], Yahoo [Bot]