Image of singular matrix in C++ Eigen using FullPivLU

here is the code I run in C++ using Eigen library FullPivLU decomposition, and I want to get the image of singular matrix including the first column of constant one rather than the other 3 columns.But the result dose not meet expectation.

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
#include <Eigen/LU>
#include <Eigen/QR>
#include <Eigen/Dense>  
#include <iostream>  
using namespace std;  
using namespace Eigen;
//*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*
//*---*---*---*---*--rank and image in LU Decomposition---*---*---*---*
//*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*---*

main()
{    
  MatrixXd X(20,4);
  MatrixXd Y(20,1);
  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;
  FullPivLU<MatrixXd> luA(X);
  luA.setThreshold(1e-6); 
  int rank = luA.rank();
  MatrixXd image = luA.image(X);
  std::cout << "rank"<< std::endl <<rank << std::endl << std::endl;  
  std::cout << "image"<< std::endl << image << std::endl << std::endl;
  system("pause");   
} 


In fact, the image of singular matrix X does not include the first column of constant one. How do I set up the luA.image(X) or is there other decomposition (like QR decomposition) can do this? Thanks in advance.
Last edited on
Well, you don't need to create luA as a FullPivLU object. When I re-wrote the code to directly set rank to X.fullPivLu().rank() and image to X.fullPivLu().image(X), it worked fine. Not sure why it doesn't work the same with the actual luA object, though.
@Ispil how did you set the luA.setThreshold(1e-6); option ?
X.fullPivLu().setThreshold(1e-6) should work.
@Ispil Well,actually, an error in X.fullPivLu().setThreshold(1e-6); occurs.
Last edited on
...huh. I have no idea, then. Either you lose a column, or you lose the right threshold...
@Ispil Anyway, thanks for your help.
Topic archived. No new replies allowed.