The LAPACK forum has moved to https://github.com/Reference-LAPACK/lapack/discussions.

zheev, zheevd wrong eigenvectors

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

zheev, zheevd wrong eigenvectors

Postby Pozarnik » Thu Mar 27, 2008 10:33 pm

Hi,

My eigenvalues appear to be correct for either zheev or zheevd. However, when I retrieve the eigenvectors there is exactly 1 correct eigenvector, the rest aren't orthonormal at all.

Could someone help please?
Pozarnik
 
Posts: 6
Joined: Mon Jan 21, 2008 2:59 pm

Non-orthonormal eigenvectors from ZHEEVx codes

Postby JimDemmel » Thu Mar 27, 2008 11:21 pm

What is your matrix for which you are having difficulty, the
calling sequence, and the output that you find problematic?
Jim Demmel
JimDemmel
 
Posts: 4
Joined: Tue Jan 09, 2007 2:17 pm

Postby Pozarnik » Fri Mar 28, 2008 12:08 am

I forgot to mention that i'm working in C, :$
Hermitian Matrices...

Here's the significant code for when i tried using zheevd_

int n=2;
int width=10;

char v='v', u='u';
int info;
double complex *A;
A=(double complex *) malloc(sizeof(double complex)*n*n);
double w[n];
int lwork = 2*n + n*n;
complex double work[lwork];
int lrwork = 1+5*n +2*n*n;
double rwork[lrwork];
int liwork = 3+5*n;
int iwork[liwork];

int width=10;
int z,i,j=0;

//randomizes a hermitian matrix with values within ->width
srand(time(NULL));
for(i=0;i<n;i++){
A[n*i+i]=width*(rand() / ((double)RAND_MAX + 1)-0.5)+0*I;
for(j=0; j<i;j++){
A[n*i+j]=width*(rand() / ((double)RAND_MAX + 1)-0.5)+width*(rand() / ((double)RAND_MAX + 1)-0.5)*I;
A[n*j+i]=creal(A[n*i+j]) + -1*cimag(A[n*i+j])*I;
}
}


zheevd_(&v,&u,&n,A,&n,w,work,&lwork,rwork,&lrwork,iwork,&liwork,&info);

The eigenvalues are in 'w', and the eigenvectors should be in 'A'.
it's the eigenvectors from A that are problematic, they're all normalized, but not orthogonal.
Pozarnik
 
Posts: 6
Joined: Mon Jan 21, 2008 2:59 pm

Postby Julien Langou » Sat Mar 29, 2008 2:04 pm

Here is a simple code that works.
You can check that A=WEW' and that W'W=I.
No idea what your problem is.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

typedef struct {
        double real, imag;
}doublecomplex;

int main()
{

    int n=4;
    int width=10;
    char v='v', u='u';
    int info;
    doublecomplex *A;


    A=(doublecomplex *) malloc(sizeof(doublecomplex)*n*n);
    double w[n];
    int lwork = 2*n + n*n;
    doublecomplex work[lwork];
    int lrwork = 1+5*n +2*n*n;
    double rwork[lrwork];
    int liwork = 3+5*n;
    int iwork[liwork];

    int z,i,j=0;

    //randomizes a hermitian matrix with values within ->width
    srand(time(NULL));
    for(i=0;i<n;i++){
        A[n*i+i].real=width*(rand() / ((double)RAND_MAX + 1)-0.5);
        A[n*i+i].imag=0.0e+00;
        printf("A(%d,%d)=%+2.10e+i*%+2.10e\n",i+1,i+1,A[n*i+i].real,A[n*i+i].imag);
        for(j=0; j<i;j++){
            A[n*i+j].real=width*(rand() / ((double)RAND_MAX + 1)-0.5);
            A[n*i+j].imag=width*(rand() / ((double)RAND_MAX + 1)-0.5);
            A[n*j+i].real=  A[n*i+j].real;
            A[n*j+i].imag= -A[n*i+j].imag;
            printf("A(%d,%d)=%+2.10e+i*%+2.10e\n",j+1,i+1,A[n*i+j].real,A[n*i+j].imag);
            printf("A(%d,%d)=%+2.10e+i*%+2.10e\n",i+1,j+1,A[n*j+i].real,A[n*j+i].imag);
        }
    }
    printf("\n");

    zheevd_(&v,&u,&n,A,&n,w,work,&lwork,rwork,&lrwork,iwork,&liwork,&info);

    for(i=0;i<n;i++){
        printf("E(%d,%d)=%+2.10e\n",i+1,i+1,w[i]);
    }
    printf("\n");

    for(i=0;i<n;i++){
        printf("W(%d,%d)=%+2.10e+i*%+2.10e\n",i+1,i+1,A[n*i+i].real,A[n*i+i].imag);
        for(j=0; j<i;j++){
            printf("W(%d,%d)=%+2.10e+i*%+2.10e\n",j+1,i+1,A[n*i+j].real,A[n*i+j].imag);
            printf("W(%d,%d)=%+2.10e+i*%+2.10e\n",i+1,j+1,A[n*j+i].real,A[n*j+i].imag);
        }
    }

    return 0;
}
Julien Langou
 
Posts: 835
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 4 guests