The DSYEV command returned incorrect eigenvalues and eigenvectors for a small 2*2 matrix. The matrix was

2 1

1 2.

Additionally instead of giving the eigenvectors back the program returned the original matrix. I looked through the bug list but could not find this kind of problem. I am using LAPACK 3.0 and my code is featured below:

#include <iostream>

#include <cstdlib>

using namespace std;

extern "C" void dsyev_(char * jobz, char * uplo, int*n, double * a, int * lda, double * w, double * work, int * lwork, int * info);

int main()

{

char jobz = 'v';

char uplo = 'u';

int n = 2;

int lda = 2;

double a[lda][n] = {{2,1},{1,2}};

double w[n];

int lwork = 10;

double work[lwork];

int info;

dsyev_(&jobz, &uplo, &n, &a[lda][n], &lda, &w[n], &work[lwork], &lwork, &info);

cout <<"The eigenvalues of the matrix are: " ;

for (int a=0; a<n; a++)

{

cout <<w[a] <<" ";

}

cout <<'\n' <<"The info is " <<info;

cout <<'\n' <<"The eigenvectors are " <<'\n';

for (int i=0; i<n; i++)

{

for (int j=0; j<lda; j++)

{

cout <<a[j][i];

}

cout <<'\n';

}

return 0;

}

My results were:

The eigenvalues of the matrix are: -1 -3.12825e-148

The info is 0

The eigenvectors are

21

12

Hopefully,

Harry