Registered Member
|
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.
|
Moderator
|
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. |
Registered Member
|
Thanks Gael. My code is now giving correct result.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]