Wrong eigenvectors for generalized eigenvalue problem

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

Wrong eigenvectors for generalized eigenvalue problem

Postby jane_miemie » Tue Nov 05, 2013 9:16 pm

Hi everyone!

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.

Code: Select all
   double AAtest[4] = {-1.999783, 0, 0, 1.999783};
   double BBtest[4] = {2.167327e-4, 1.999783, 1.999783, 0};
   int i, j, N = 4;
   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:
Code: Select all
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
Code: Select all
-0.500000000733645 - 0.499999999266355i   -0.500000000733645 + 0.499999999266355i
0.500027093059538 - 0.499972905472315i   0.500027093059538 + 0.499972905472315i


pls help...Thanks!
jane_miemie
 
Posts: 1
Joined: Tue Nov 05, 2013 9:05 pm

Re: Wrong eigenvectors for generalized eigenvalue problem

Postby cbrunow » Wed Jan 08, 2014 7:06 am

eigenvectors are not unique. For one thing, the signs could all be reversed and they can be scaled. Have you checked that they are mutually orthogonal? If they satisfy the equation they are valid even though they are different.
cbrunow
 


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 1 guest