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

Dealing with complex double type

Tags: None
(comma "," separated)
jrussel
Registered Member
Posts
2
Karma
0

Dealing with complex double type

Sat Aug 04, 2012 10:32 pm
So, apologies in advance for what I know has to be a total newbie question.

I'm trying to extract eigenvalues into a simple array just to do an additional manipulation and then be able to write them neatly to a file. The problem is that, when using EigenSolver, the (default?) output type of the vector of eigenvalues is complex double (since the array was type double) so I get an error from type mis-match. Is there any way to force EigenSolver to output only the real part of the eigenvectors, or alternatively is there any way to cast complex objects to real in Eigen? As I said, I'm not an incredibly proficient programmer so most of the documentation here has been too abstract for me to get anything out of.

Edit: The 3.0 change log says that complex numbers are vectorized which should me I would be able to access the real part using the [] operator, but that just returns an error.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
If you known the eigenvalues must be real, then you can do:

EigenSolver<...> eig(A);
VectorXd eivals = eig.eigenvalues().real();

".real()" returns a "view" on the real parts.
jrussel
Registered Member
Posts
2
Karma
0
Ok, it was really just that easy. Thank you, that was exactly what I was looking for.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]