Registered Member
|
Hi all,
I'm trying to replace Octave in a custom simulation by Eigen. In total, it was very smooth, but I got totally stuck with the QR decomposition. For the determination of some residual, I need both Q and R matrices, but I did not make it by matrixQ() from FullPivHouseholderQR. Also, I was not able to determine the data format returned by matrixQR(). The only hint is that it is compatible to Lapack (even though I found a discussion, whether this is really the case...). But also getting the format Lapack uses, was out of reach for me (sorry for my incompetence...). So, my question is, can anyone tell me, how to extract Q from the return of matrixQR? Here is my test program, with which i tried to figure out, what is happening:
The output is
Any help?!?!?! Thanks a lot! Hecke |
Moderator
|
matrixQ() returns a proxy object representing the matrix Q as a combination of a permutation and q householder sequence, but you can simply do:
MatrixXd Q = qr.matrixQ(); to get a standard matrix.BTW, do you really need full pivoting? |
Registered Member
|
hi Ggael,
thanks a lot for your reply. I tried
as you can see in my example code. But unfortunately, the result does not seem to be the Matrix that fits into A = Q*R which should be the same as Q = A*R.inverse() which is matrix q (which is not equal to the output of MatrixXd Q = qr.matrixQ(); ) in my example. What did I get wrong? Full pivoting... hm. I am dealing with a quite complex flow solver which was written by someone else, and I just jumped into it. So I cannot really say. Maybe we can drop the accuracy of the full pivoting and go to the simple HouseholderQr(), but there is no function qr.matrixQ() available at all, right? thanks again Hecke |
Registered Member
|
OH, as it was Friday, I did not see that in my example the second to last matrix (Q*R) is A with the first and second column switched...
So, maybe Q uses a different sorting of the columns according to the pivoting, correct? How can I adjust for this? thanks Hecke |
Moderator
|
the factorisation is A * P = Q * R;
you can get P via the colsPermutation() function. You can apply it to a matrix as usual, and apply the inverse using the ... .inverse() method! |
Registered Member
|
Hi Ggael,
thanks again for your help. In the meantime I dug a bit deeper in the code, and saw that the QR decomposition was primarily used to solve a linear equation system by hand, so I can use the solve() function!
This seems to do the job, but now I have a different problem, presumably not with Eigen... thanks a lot and keep up the good work! Hecke |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]