Reply to topic

Newcomer's question regarding inversion of complex matrix

nbanerjee
Registered Member
Posts
2
Karma
0
I am new to Eigen as well as C++ programming. However, I am trying to write a code in c++ for calculating inverse of a complex matrix using Eigen. The complex matrix has a size 50x50 to 200x200 and, only20% of elements of this matrix are nonzero. I use .inverse(), .solve() with identity matrix for this purpose. But, none of the method produce correct results, however using mathematica I can get correct result. May be I am making some basic mistakes in choosing appropriate module in eigen. I shall be highly obliged if you could describe the correct method elaborately. Thanks in advance.
User avatar ggael
Moderator
Posts
2194
Karma
15
OS
Make sure you properly initialized the matrix to zero:

MatrixXcd m(rows,cols);
m.setZero();
m(i,j) = ...;
....


otherwise the non specified entries will contain random values.

Then simply do:

MatrixXcd invMat = mat.inverse();

If your matrix is not singular this should be enough.
nbanerjee
Registered Member
Posts
2
Karma
0
Thanks Gael. My code is now giving correct result. :)

 
Reply to topic

Bookmarks



Who is online

Registered users: alake, Baidu [Spider], Bing [Bot], Exabot [Bot], garthecho, Google [Bot], google01103, Hans, hmethorst, industrie13, jensreuterberg, koriun, l3u, La Ninje, mmistretta, nerdopolis, PaddyMac, pedrorodriguez, SecretCode, Sentynel, VictorL, Yahoo [Bot]