There might exist some bugs in dsygvd and dsygv. My program is listed below
I chosed the shared version (statically-linked, debug) of CLapack.
#include "stdafx.h"
#include <iostream>
using namespace std;
extern "C"{
#include <f2c.h>
#include <dsygvd.h>
};
int _tmain(int argc, _TCHAR* argv[])
{
integer itype;
itype=1;
char jobz;
jobz='V';
char uplo;
uplo='U';
integer n;
n=3;
double a[]={2,-1,-1,-1,4,-3,-1,-3,4};
integer lda;
lda=3;
double b[]={2,0,0,0,4,0,0,0,5};
integer ldb;
ldb=3;
double *w;
w=new double[3];
double *work;
work=new double;
integer lwork;
lwork=-1;
integer *iwork;
iwork=new integer;
integer liwork;
liwork=-1;
integer info;
int r;
r=dsygvd_(&itype,&jobz,&uplo,&n,a,&lda,b,&ldb,w,work,&lwork,iwork,&liwork,&info);
cout<<"the info is "<<info<<endl;
cout<<"eigenvalues are "<<endl;
cout<< w[0] <<" "<< w[1]<<" "<<w[2]<<endl;
cout<<"eigenvector are "<<endl;
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<endl;
return 0;
}
the results are :
the info is 0
eigenvalues are
-6.27744e+066 -6.27744e+066 -6.27744e+066
eigenvector are
2 -1 -1 -1
but the true results are
>> a
a =
2 -1 -1
-1 4 -3
-1 -3 4
>> b=[2 0 0;0 4 0;0 0 5]
b =
2 0 0
0 4 0
0 0 5
>> [v,d]=eig(a,b)
v =
-0.301511344577764 0.631598976285902 0.100864474645485
-0.301511344577764 -0.081584465022301 -0.390429102601143
-0.301511344577764 -0.187372018496520 0.271997492222721
d =
0.000000000000000 0 0
0 1.212917130661302 0
0 0 1.587082869338698

