Reply to topic

Prblem with inversion matrix with eigen

mdaakir
Registered Member
Posts
4
Karma
0
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.

Can you please help me ?

Thank you.
User avatar ggael
Moderator
Posts
2195
Karma
15
OS
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
thank you for your answer.

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
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
User avatar ggael
Moderator
Posts
2195
Karma
15
OS
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);

 
Reply to topic

Bookmarks



Who is online

Registered users: Alexa [Bot], Baidu [Spider], Bing [Bot], dniitall, Exabot [Bot], Google [Bot], google01103, koriun, Majestic-12 [Bot], north, ooker, paulus3005, psbot [Picsearch], rdorsch, rulet111, scummos, SecretCode, Uri_Herrera, vascobasque, wimwillemsen, Yahoo [Bot]