Registered Member
|
Hi think the documentation lacks of information on usage of matrices defined with std::complex scalar type.
For example, how can I extract the imaginary part and save it on a new matrix starting from
without explicitly looping over the matrix with for loops?
|
Moderator
|
|
Registered Member
|
if I had two sparse matrix A and B, could I obtain a third matrix C as:
complex<double> C(A,B) ? If guess that's not working well. Any idea? |
Moderator
|
In two steps:
MatrixXc C(m,n); c.real() = A; c.imag() = B; |
Registered Member
|
The same procedure doesn't work if C is a sparse matrix. I have:
Why? |
Moderator
|
Indeed with a sparse representation such operations are not possible in general, thus not allowed. A workaround:
C = A.cast<complex<double> >() + B.cast<complex<double> >(); If A and B have the same sparcity pattern, this should be pretty fast (I hope the compiler will be able to remove the additions with 0). |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]