I have tried to solve for the eigenvalues of a general symmetric matrix.
To test that in C I have written the following programm for a diagonal 4x4 unit matrix:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<lapacke.h>
main()
{
double *AP,*w,*z,*WORK;
char JOBZ='V',UPLO='U';
lapack_int INFO,M=4;
float A[M*(M+2)+1];
AP=calloc(M*(M+1)/2+1,sizeof(double));
w=calloc(M+1,sizeof(double));
z=calloc(M*(M+2)+1,sizeof(double));
WORK=calloc(3*M+1,sizeof(double));
int ii,jj;
// initialization
for(ii=0;ii<=M;++ii)
{
for(jj=0;jj<=M;++jj)
{
A[(M+1)*jj+ii]=0;
}
}
//filling the matrix
for(ii=1;ii<=M;++ii)
{
A[(M+1)*ii+ii]=1.0;
}
// filling done
//filling AP
for(ii=1;ii<=M;++ii)
{
for(jj=ii;jj<=M;++jj)
{
AP[ii+jj*(jj-1)/2]=A[(M+1)*jj+ii];
}
}
//AP done
INFO=LAPACKE_dspev(LAPACK_COL_MAJOR,JOBZ,UPLO,M,AP,w,z,M); // finding the eigenvalues
//printing the eigenvalues
for(ii=1;ii<=M;++ii)
{
printf("%e\n",w[ii]);
}
//done
}
But the result is quite absurd. Please help me out.
Anjan