|Re: [eigen] QR factorization question|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
On Wed, 26 Aug 2009, Eric Chu wrote:
great! that solved my problem.
i have another issue though: A is a skinny matrix (m > n), and the matrix Q
is square (m x m).
how do i retrieve the appropriate Q matrix that goes with my (now) upper
triangular R? (i.e. A = [Q1 Q2] [R1; 0]--or the "economy size decomposition"
To get "economy size decomposition", you just have to select the right
submatrices. The standard QR decomposition writes A = QR where Q is m x m
and R is m x n, but the last (m-n) rows of R are zero. The economy-size
decomposition throws away the last (m-n) rows of R and the last (m-n)
columns of Q, so you get A = QR where Q is m x n and R = n x n.
Here's some code to get you going:
const int m = 3;
const int n = 2;
A << 1,6, 3,8, 7,3;
cout << "A = " << endl << A << endl;
MatrixXd Q = qrOfA.matrixQ().block(0,0,m,n);
cout << "Q = " << endl << Q << endl;
MatrixXd R = qrOfA.matrixQR().block(0,0,n,n).triangularView<UpperTriangular>();
cout << "R = " << endl << R << endl;
I believe that this is rather inefficient, in that Eigen stores the full
QR decomposition (Q is m x m), while you need only the economy-size one.
Matlab commands for comparison:
>> A = [1,6;3,8;7,3]
>> [Q,R] = qr(A,0)
Hope this helps.