Incorrect eigenvectors while using DGEEV

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

Incorrect eigenvectors while using DGEEV

Postby Cleaner_86 » Thu Oct 09, 2014 10:01 pm

So i've been trying to diagonalize a real symmetric matrix using dgeev. The code's been written in C.I do get the correct eigenvalues but the eigenvectors are incorrect (i've checked it with matlab) and i don't understand why this is happening. Any help on this would be deeply appreciated.




Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 4
#define size 2*N


int main()
{
double **A,*AT;
double b1[size],b2[size],b_1[size],m[size][size],ER[size][size],WORK[4*size];
int d[size];
float t1[3],t2[3],E[2];
double DUMMY[1][1];
int i,j,nu,l,k,mu,p,q=0,v,u=0,site=0,c1,c2,c3,c6,ok;
char c4,c5;

t1[0]=0.15;t1[1]=0.05;t1[2]=0.10;t2[0]=0.075;t2[1]=0.025;t2[2]=0.075;

A=malloc( size * sizeof (int));
AT=malloc(size*size*sizeof(int));
for(i=0;i<size;i++){
A[i]=malloc(size * sizeof(int));B[i]=malloc(size * sizeof(int));
}

for(i=1;i<N+1;i++){u=0;
for(mu=0;mu<2;mu++){p=0;
for(j=1;j<N+1;j++){

/* t1 connections */

if(i!=j){
if( abs(j-i)==1 || abs(j-i)==N-1){
for(nu=0;nu<2;nu++){
v=nu+u;
A[i+mu+q-1][j+nu+p-1]=t1[v];
}
}

/*t2 connectins */

else if( abs(j-i)==2 || abs(j-i)==N-2){
for(nu=0;nu<2;nu++){
v=nu+u;
A[i+mu+q-1][j+nu+p-1]=t2[v];
}
}


else{
for(nu=0;nu<2;nu++){
A[i+mu+q-1][j+nu+p-1]=0.0;
}
}
}

else{

for(nu=0;nu<2;nu++){

if(i+mu+q==j+nu+p){
A[i+mu+q-1][j+nu+p-1]=E[nu];
}

else{
A[i+mu+q-1][j+nu+p-1]=0.0;
}
}

}
p=p+1;
}
u=u+1;
}
q=q+1;
}


for(i=0;i<size;i++){
for(j=0;j<size;j++){
printf("%.2f ",A[i][j]);
}
printf("\n");
}
for (i=0; i<size; i++)       
{                               
  for(j=0; j<size; j++)
  {
     AT[(j+size*i)]=A[j][i];

  }
}



c1=size;                       
c2=2*size;                   
c3=1;                           
c4='N';
c5='V';
c6=4*size;     

dgeev_(&c4,&c5,&c1,AT,&c1,b1,b2,DUMMY,&c3,ER,&c1,WORK,&c6,&ok);

if (ok==0)                              /* output of eigenvalues */
{
printf("Eigenvalues\n");
for(i=0;i<size;i++){
printf("%d\t%lf\n",i+1,b1[i]);
}
}
else printf("error in computing eigenvalues\n");


printf ("Eigenvectors\n");
for(i=0;i<size;i++){printf("%d\n",i+1);
for(j=0;j<size;j++){
printf("%.4f\n",ER[j][i]);
}
printf("\n");
}






                                                                                                                                           1,1           Top

Cleaner_86
 
Posts: 1
Joined: Thu Oct 09, 2014 9:40 pm

Re: Incorrect eigenvectors while using DGEEV

Postby admin » Fri Oct 10, 2014 1:55 am

please see viewtopic.php?f=2&t=3573

To easily call LAPACK form C, you can use LAPACKE, the LAPACK C Standard interface.
http://www.netlib.org/lapack/#_standard ... for_lapack

Hope it helps
admin
Site Admin
 
Posts: 616
Joined: Wed Dec 08, 2004 7:07 pm


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 39 guests