This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Newcomer's question regarding inversion of complex matrix

Tags: None
(comma "," separated)
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
3447
Karma
19
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. :)


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]