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

mapping a complex matrix

Tags: None
(comma "," separated)
bobo01
Registered Member
Posts
10
Karma
0

mapping a complex matrix

Sun Jan 11, 2015 2:40 pm
Hello

I have the following matrix

Code: Select all
int N = 3;
    complex<double>* complexvector = new complex<double>[N];// allocate an array of pointers
    for(int i=0; i<N; i++)
           {
              complexvector[i]=complex<double>(i+1,i+1);
           }



    complex<double>** complexMatrix = new complex<double>*[N];// allocate an array of pointers
       for(int i=0; i<N; i++)
       {
          complexMatrix[i] = new complex<double>[N];// allocate an array to each pointer
    //      //for(int j=0; j<N; j++)
    //      //   complexMatrix[i][j]=complex<double>(3.0,3.0);
       }

complexMatrix[0][0] = complex<double>(1,1);
    complexMatrix[0][1] = complex<double>(2,2);
    complexMatrix[0][2] = complex<double>(3,3);

    complexMatrix[1][0] = complex<double>(4,4);
    complexMatrix[1][1] = complex<double>(5,5);
    complexMatrix[1][2] = complex<double>(6,6);

    complexMatrix[2][0] = complex<double>(7,7);
    complexMatrix[2][1] = complex<double>(8,8);
    complexMatrix[2][2] = complex<double>(9,9);



Then I try to map it to do a Cholesky decomposition

Code: Select all

   complex<double>* returnvector = new complex<double>[N];
       returnvector = preformcholesky(complexMatrix, complexvector, N);

complex<double>* preformcholesky(complex<double>** matrix, complex<double>* vector, int  size)
{
   std::cout << "start cholesky" << std::endl;
   Map<MatrixXcd, RowMajor> mat(*matrix,size,size);
   Map<VectorXcd> vec(vector,size);
   std::cout << "start cholesky2" << std::endl;
   printMatrix(matrix,size);
   std::cout << "mat" << mat << std::endl;
   std::cout << "vec" << vec << std::endl;
   VectorXcd x = mat.llt().solve(vec);
   std::cout << "coeff" << x << std::endl;
   return x.data();
}



When I print "mat", I have the following values:

Code: Select all
mat           (1,1) (0,3.21143e-322)            (6,6)
           (2,2)            (4,4) (0,3.21143e-322)
           (3,3)            (5,5)            (7,7)



Where did these come from, (0,3.21143e-322) ? When I print "matrix", it is correct, meaning the Map function has gone wrong.
bobo01
Registered Member
Posts
10
Karma
0

Re: mapping a complex matrix

Mon Jan 12, 2015 4:37 pm
The answer is that Eigen expects a flat array.


Bookmarks



Who is online

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