Question

I'm using LAPACKE to solve generalized eigenvalue problem A*V = lambda*B*V and I need both eigenvalues and right eigenvectors. But the problem is I can only get correct eigenvalues but wrong eigenvectors. Actually I've used my code to test the example in this link http://www.nag.com/numeric/FL/nagdoc_fl22/examples/baseresults/f08ykfe.r. It's successful. So I'm wondering why it doesn't work for this case. I'd post my code and results below. Can anybody tell me give me a hint? Thanks a lot.

double AAtest[4] = {-1.999783, 0, 0, 1.999783};
double BBtest[4] = {2.167327e-4, 1.999783, 1.999783, 0};
int i, j, N = 2;
int matrix_order = LAPACK_COL_MAJOR;
double *RR, *QQ, *ZZ, *alphar, *alphai, *beta;
int *select, m;
int info1, info2, info3, info4, info5, info6, info7;
int ilo, ihi;
double *lscale, *rscale, *tau;

RR = (double *)calloc(N*N, sizeof(double));
QQ = (double *)calloc(N*N, sizeof(double));
ZZ = (double *)calloc(N*N, sizeof(double));
alphar = (double *)calloc(N, sizeof(double));
alphai = (double *)calloc(N, sizeof(double));
beta = (double *)calloc(N, sizeof(double));
select = (int *)calloc(N, sizeof(int));
lscale = (double *)calloc(N, sizeof(double));
rscale = (double *)calloc(N, sizeof(double));
tau = (double *)calloc(N, sizeof(double));

for (i = 0; i < N; i++)
    select[i] = 1;

info1 = LAPACKE_dggbal(matrix_order, 'B', N, AA, N, BB, N, &ilo, &ihi, lscale, rscale);
info2 = LAPACKE_dgeqrf(matrix_order, N, N, BB, N, tau);
for (i = 0; i < N; i++){
    for (j = i; j < N; j++){
        RR[j*N+i] = BB[j*N+i];
        BB[j*N+i] = 0;
    }
}
info3 = LAPACKE_dormqr(matrix_order, 'L', 'T', N, N, N, BB, N, tau, AA, N);
info4 = LAPACKE_dgghrd(matrix_order, 'I', 'I', N, ilo, ihi, AA, N, RR, N, QQ, N, ZZ, N);
info5 = LAPACKE_dhgeqz(matrix_order, 'S', 'V', 'V', N, ilo, ihi, AA, N, RR, N, alphar, alphai, beta, QQ, N, ZZ, N);
info6 = LAPACKE_dtgevc(matrix_order, 'R', 'B', select, N, AA, N, RR, N, QQ, N, ZZ, N, N, &m);
info7 = LAPACKE_dggbak(matrix_order, 'B', 'R', N, ilo, ihi, lscale, rscale, m, ZZ, N);

Results:

Input matrix AA....................................
-1.999783e+00   0.000000e+00
0.000000e+00    1.999783e+00
Input matrix BB....................................
2.167327e-04    1.999783e+00
1.999783e+00    0.000000e+00
After balancing AA...................
-1.999783e+02   0.000000e+00
0.000000e+00    1.999783e+00
After balancing BB...................
2.167327e-02    1.999783e+01
1.999783e+01    0.000000e+00
R factor.............................
-1.999784e+01   -2.167326e-02
0.000000e+00    -1.999782e+01
Q'*A.................................
2.167326e-01    -1.999782e+00
1.999782e+02    2.167326e-03
Hessenberg form of AA................
2.167326e-01    -1.999782e+00
1.999782e+02    2.167326e-03
triangular form of BB................
-1.999784e+01   -2.167326e-02
0.000000e+00    -1.999782e+01
Eigenvalues..........................
-0.000054 + j1.000000
-0.000054 + j-1.000000
Schur form of AA................
-9.904398e+01   1.009890e+02
-1.009890e+02   9.893453e+01
Schur form of BB................
2.000867e+01    0.000000e+00
0.000000e+00    1.998700e+01
Right eigenvectors.....................
-9.090507e-02   9.090506e-01
-9.090457e-01   -9.095433e-02

But when I use matlab to solve this problem, the eigenvectors I got is

-0.500000000733645 - 0.499999999266355i -0.500000000733645 + 0.499999999266355i
0.500027093059538 - 0.499972905472315i  0.500027093059538 + 0.499972905472315i

pls help...Thanks!

Was it helpful?

Solution

Solved this problem by only calling LAPACKE_dggev. This function would call those routines automatically. Not sure about whether it would balance the matrix or not. At least now the results match with matlab results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top