This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to Get Matrix Q in QR decomposition?

Tags: None
(comma "," separated)
User avatar
piyifan
Registered Member
Posts
2
Karma
0
I am confused with the function of HouseholderQr.
1. If I have a matrix M with size m * n (let m > n). I want get the orthogonal columns Q of M just like
the Matlab command [Q,R]=qr(M,0). But if I use Q = M.householderQr().matrixQ(), I find that Q
has a size m * m not m * n as expected. So how can I obtain the right Q like Matlab.
2. As the help said, matrixQ() returns a Householder sequence but not a matrix. It seems faster if
we store a Householder sequence, and use Householder reflection instead of using matrix multiplication.
But there is lack of documentation describing how to do this, can any one give an example?

Thanks!! ^-^ ^-^
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I'm sorry but by definition the 'right' Q matrix is a squared unitary matrix. Here is an example showing how to compute the 'thin' Q. This example also shows how to directly use the returned householder sequence for matrix products:
Code: Select all
#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;

int main()
{
  MatrixXf A(10,5), thinQ(10,5), Q(10,10);
  A.setRandom();
  HouseholderQR<MatrixXf> qr(A);
  Q = qr.householderQ();
  thinQ.setIdentity();
  thinQ = qr.householderQ() * thinQ;

  std::cout << Q << "\n\n" << thinQ << "\n\n";
}
User avatar
piyifan
Registered Member
Posts
2
Karma
0
Thanks!
But can you provide an example on how to compute the product Q*N (N is another matrix)
directly using householder reflection? (Because storing Q of size m * m is hard).
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
just do qr.householderQ() * N !!


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]