## Newcomer's question regarding inversion of complex matrix

nbanerjee
Registered Member
Posts
2
Karma
0

### Newcomer's question regarding inversion of complex matrix

Mon Mar 25, 2013 6:14 am
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.
ggael
Moderator
Posts
2695
Karma
17
OS

### Re: Newcomer's question regarding inversion of complex matri

Mon Mar 25, 2013 1:13 pm
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

### Re: Newcomer's question regarding inversion of complex matri

Wed Mar 27, 2013 3:08 pm
Thanks Gael. My code is now giving correct result.

## Who is online

Registered users: AdsBot [Google], Artmessiah, Baidu [Spider], Bing [Bot], BlaXpirit, drosca, Exabot [Bot], Google [Bot], google01103, gregormi, hftom, jlsils, koriun, kostaukrainekosta, La Ninje, louis94, Majestic-12 [Bot], MSNbot Media, narcisgarcia, nbelavic, rbruce, ripper17, scummos, Steve T, vpinon, YaCy [Bot], Yahoo [Bot]