how do I get non-singular matrix using C++ Eigen QR decomposition

Here is the code I run in C++ using Eigen library ColPivHouseholderQR decomposition, and I have got the rank of matrix and want to get the non-singular matrix. But I do not know which function in QR decomposition can do this.Any help will be very appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <Eigen/LU>
#include <Eigen/QR>
#include <Eigen/Dense>  
#include <iostream>  
using namespace std;  
using namespace Eigen;
//*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*
//*---*---*---*---*--rank and image in QR Decomposition---*---*---*---*
//*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*

main()
{
  MatrixXd X(20,4);
  MatrixXd Y(20,1);
  MatrixXd X1(20,5);
  //int n=20,p=4;
  X <<1,1,0,0
     ,1,1,0,0
     ,1,1,0,0
     ,1,1,0,0
     ,1,1,0,0
     ,1,0,2,0
     ,1,0,2,0
     ,1,0,2,0
     ,1,0,2,0
     ,1,0,2,0
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3
     ,1,0,0,3.000001;
  Y <<50,51,52,54,53,60,59,65,67,70,70,73,74,78,82,80,87,84,88,92;
  X1<<X,Y;
  ColPivHouseholderQR<MatrixXd> qrA(X1);
  qrA.setThreshold(1e-7); 
  int rank = qrA.rank();
  std::cout << "rank"<< std::endl <<rank << std::endl << std::endl;  
  //std::cout << "image"<< std::endl << image << std::endl << std::endl;
  system("pause");   
}
Topic archived. No new replies allowed.