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

Solving Complex Linear System

Tags: None
(comma "," separated)
Shikashy
Registered Member
Posts
3
Karma
0

Solving Complex Linear System

Sun Feb 28, 2016 2:04 pm
Hey Eigen !

First of all, I apologize for my english, it is not my mother tongue.

Here is my question :

I have a complex matrix A and a complex vector b. I would like to solve the linear system Ax=b.
I tried to use the example on this page, and adapt it to my complex problem. (http://eigen.tuxfamily.org/dox/group__TutorialLinearAlgebra.html)


Here is a simplified example of what i'm trying to do :

My object are defined this way :
Code: Select all
typedef Eigen::Matrix<complexd, Eigen::Dynamic, Eigen::Dynamic> DoubleComplexMatrix;
typedef Eigen::Array<complexd, Eigen::Dynamic, 1> DoubleComplexArray;


And in my code I want to solve this
Code: Select all
   DoubleComplexMatrix A(3,3);
   DoubleComplexArray b(3);
   DoubleComplexArray x(3);

   A << 1,2,3,  4,5,6,  7,8,10;
   b << 3, 3, 4;
   cout << "Here is the matrix A:\n" << A << endl;
   cout << "Here is the vector b:\n" << b << endl;
   
   ColPivHouseholderQR<DoubleComplexMatrix> dec(A);
  x = dec.solve(b);
   cout << "The solution is:\n" << x << endl;


The error appears at the line : DoubleComplexArray x = dec.solve(b); because when I comment it, there is no more error.

I get this error :
TideSolve.cpp:98:38: error: no matching function for call to ‘Eigen::ColPivHouseholderQR<Eigen::Matrix<std::complex<double>, -1, -1> >::solve(DoubleComplexArray&)’
DoubleComplexArray x = dec.solve(b);

Here is finally my question:
Does that mean that eigen solvers does not work with complex ? (I'm sure they do, and I'm just bad ! )
Do I need another solver than ColPivHouseholderQR that work with complexs ? If so, can someone tell me which one ?

Thank you very much for your help and time. Once again, I apologize for my english.
If this subject has already been covered somewhere, I also apologize: I did not find it...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Shikashy
Registered Member
Posts
3
Karma
0

Re: Solving Complex Linear System

Tue Mar 01, 2016 10:26 pm
Thank you very much for your answer and considering my question. SO indeed helped me fixed my problem.

But I have to admit it is pretty slow. It took 2 hours to solve a 1800*1800 matrix. Do you think it is a normal time ? I admit I have no idea what are normal compuation time for these kind of calculus.

I compile using : g++ -o main *.cpp
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Don't forget to enable compiler optimizations: with the -O3 flag. It then should be several order of magnitude faster ;)
Shikashy
Registered Member
Posts
3
Karma
0

Re: Solving Complex Linear System

Thu Mar 03, 2016 9:03 am
Thank you very much !

When I did this I had several error in my codes (mostly warnings) but now it works just fine and it's so much faster !


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft