## Getting Q and R out of HouseHolderQR (eigen 3.0.4)

BenBenBen
Registered Member
Posts
2
Karma
0

### Getting Q and R out of HouseHolderQR (eigen 3.0.4)

Mon Jan 16, 2012 5:58 pm
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 LAPACK-compatible 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 row-wise vs column-wise 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
Posts
2
Karma
0

### Re: Getting Q and R out of HouseHolderQR (eigen 3.0.4)

Tue Jan 17, 2012 10:11 am
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
Posts
204
Karma
2

### Re: Getting Q and R out of HouseHolderQR (eigen 3.0.4)

Tue Jan 17, 2012 10:19 am
Yes, to both question. It seems that the documentation of the HouseHolderQR class can be greatly improved. A patch would be very welcome.
Registered Member
Posts
3
Karma
0

### Re: Getting Q and R out of HouseHolderQR (eigen 3.0.4)

Mon Mar 23, 2015 8:08 pm
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
Posts
2660
Karma
16
OS

### Re: Getting Q and R out of HouseHolderQR (eigen 3.0.4)

Mon Mar 23, 2015 8:51 pm
I guess you are referring to the column-pivoting 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".
Registered Member
Posts
3
Karma
0

### Re: Getting Q and R out of HouseHolderQR (eigen 3.0.4)

Mon Mar 23, 2015 9:02 pm
subhadeepk wrote: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?

I found the solution, so I am reporting (Might help somebody like me ) .

qr.compute(A);
MatrixXd P = qr.colsPermutation();

## Who is online

Registered users: aurorelb, Baidu [Spider], Bing [Bot], boudewijn, capslock, davidemme, drosca, Exabot [Bot], gavinc, Google [Bot], google01103, koriun, M4he, Majestic-12 [Bot], marcuschristopher, MSNbot Media, pranavar, rodorapido, rv8ter, ttguy, utterucalls, veqz, vicnet, wolfi323, Xiceph, Yahoo [Bot]