## Prblem with inversion matrix with eigen

mdaakir
Registered Member
Posts
4
Karma
0

### Prblem with inversion matrix with eigen

Sun Sep 15, 2013 12:16 pm
Hello,

I have one problem while computing some matrix inversion with Eigen library.
I implement a least square algorithm, and I do it iteratively. I did the same thing under matlab and it's working well, so the problem is that I can't succeed to do the inversion under Eigen.

This how it look like :

for(int i=0; i<50; i++) //iterations
{
//all the other matrices are fine
.....
//eqnormal equation
Eigen::MatrixXd S(24,12); //declare the matrice
S=(Qll*G.transpose())*(G*Qll*G.transpose()).inverse(); //where I do the inversion
}

the first time, I got the good result for S. After the second iteration, I have only "NaN" inside.

Thank you.
ggael
Moderator
Posts
2145
Karma
15
OS

### Re: Prblem with inversion matrix with eigen

Sun Sep 15, 2013 1:09 pm
You matrix is likely not invertible. You can use inverseWithCheck to verify that. However the best is to avoid the explicit computation of the inverse by factorizing it and call solve method to apply A^-1. E.g.:
Code: Select all
`HouseholderQR<MAtrixXd> qr(A);x = qr.solve(b); // computes A^-1 * b`

Also, you should store Qll*G.transpose() into a temporary matrix to avoid computing it twice.
mdaakir
Registered Member
Posts
4
Karma
0

### Re: Prblem with inversion matrix with eigen

Sun Sep 15, 2013 2:30 pm

The problem is, I want to do something like, b*A^-1
I took you advice into account and I have :
Eigen::MatrixXd s1(24,12); s1.setZero(); //temporary matrix
s1=Qll*G.transpose();
Eigen::MatrixXd s2(12,12); s2.setZero();//matrice temporaire
s2=G*s1;
//Eigen::MatrixXd S(24,12); S.setZero(); //the matrix with inversion
//S=(s1)*(s2.inverse()); //not working

How should I use : HouseholderQR<MAtrixXd> ?
HouseholderQR<MAtrixXd> qr(s2);
S=qr.solve(s1); // here the result is then S=s2^-1 * s1
and what I want is : S=s1*s2^-1

thanks again for your help
mdaakir
Registered Member
Posts
4
Karma
0

### Re: Prblem with inversion matrix with eigen

Sun Sep 15, 2013 2:52 pm
sorry that was stupid question, i can use identity to compute : s3=s2^-1 * id
Now I do :
Eigen::MatrixXd s1(24,12); s1.setZero();//matrice temporaire
s1=Qll*G.transpose();
Eigen::MatrixXd s2(12,12); s2.setZero();//matrice temporaire
s2=G*s1;

Eigen::MatrixXd id(12,12); id.setIdentity();
Eigen::MatrixXd s3(12,12); s3.setZero();

Eigen::HouseholderQR<Eigen::MatrixXd> qr(s2);
s3=qr.solve(id); //s3=s2^-1 * id

Eigen::MatrixXd S(24,12); S.setZero();
S=s1*s3;

I have one message error : variable 'Eigen::HouseholderQR<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001> > qr' has initializer but incomplete type

can you help me with this please ?

Thanks again
ggael
Moderator
Posts
2145
Karma
15
OS

### Re: Prblem with inversion matrix with eigen

Sun Sep 15, 2013 8:40 pm
You need to include Eigen/QR and transpose everything:

s1=G*Qll.transpose();
s2=s1*G1.transpose();
Eigen::HouseholderQR<Eigen::MatrixXd> qr(s2);
s.transpose() = qr.solve(s1);

## Who is online

Registered users: alake, Baidu [Spider], Bequimao, Bing [Bot], colomar, CountChocula, Exabot [Bot], Google [Bot], Hei Ku, jgrulich, kde-particleman, lazyit, legnaVI, Leroux, Majestic-12 [Bot], mbohlender, MSNbot Media, plaristote, sandsmark, sir_herrbatka, trebor, verbalshadow, wperkins, Yahoo [Bot]