LAPACKE_dsyevd returns wrong eigenvectors

137 views Asked by At

I am very far from being a great programmer and I am trying to use LAPACKE_dsyevd. I wrote the following code which aims to find out the eigenvalues and eigenvectors of a 2x2 symmetric matrix whose diagonal is made of 0 and non diagonal elements are equals to 1. The eigenvalues are the good ones, but only one of the return eigenvectors is good. I tried several combinations of the parameters without any success ... Can someone tell me what is wrong?

#include <stdlib.h>
#include <stdio.h>
#include <iostream>

#include <lapacke.h>

using namespace std;

int main() {

    int n, lda, info,i,j;
    char jobz, uplo;

    n=2;
    lda=n*(n+1)/2;
    jobz='V';
    uplo='U';

    //double a[lda];
    double a[n*n];

    a[0]=0 ; a[1]=1; a[2]=0; a[3]=1;

    double w[n];

   info = LAPACKE_dsyevd (LAPACK_ROW_MAJOR, jobz, uplo, n, a, lda, w);

   cout << " Eigenvalues: ";
   for(i=0; i< n ;++i)
        cout << w[i] << " ";
   cout << endl<<endl;

   cout << " Eigenvectors:";
   for(i=0; i< n ; ++i)
   {
       for (j=0;j<n; j++)
            cout << a[i+n*j] << " ";
       cout <<endl;
   }

    return 0;
}

0

There are 0 answers