CODE not working properly

Open discussion regarding features, bugs, issues, vendors, etc.

CODE not working properly

Postby anjansarkarbhp » Thu Aug 27, 2015 1:15 am

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
anjansarkarbhp
 
Posts: 2
Joined: Thu Aug 27, 2015 1:08 am

Re: CODE not working properly

Postby admin » Thu Aug 27, 2015 1:35 am

LAPACKE_dspev is for matrices in packed format.

See LAPACK routine name scheme
http://www.netlib.org/lapack/lug/node24.html

You may want to use DSYEV (symmetric format )
Hope it helps
admin
Site Admin
 
Posts: 614
Joined: Wed Dec 08, 2004 7:07 pm

Re: CODE not working properly

Postby anjansarkarbhp » Thu Aug 27, 2015 3:19 am

Thank you very much. It works.

Anjan
anjansarkarbhp
 
Posts: 2
Joined: Thu Aug 27, 2015 1:08 am


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 6 guests