我正在使用 LAPACKE 来解决广义特征值问题 A*V = lambda*B*V 并且我需要特征值和右特征向量。但问题是我只能得到正确的特征值但错误的特征向量。实际上,我已经使用我的代码来测试此链接http://www.nag.com/numeric/FL/nagdoc_fl22/examples/baseresults/f08ykfe.r中的示例。这是成功的。所以我想知道为什么它不适用于这种情况。我会在下面发布我的代码和结果。谁能告诉我给我一个提示?非常感谢。
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);
结果:
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
但是当我使用matlab解决这个问题时,我得到的特征向量是
-0.500000000733645 - 0.499999999266355i -0.500000000733645 + 0.499999999266355i
0.500027093059538 - 0.499972905472315i 0.500027093059538 + 0.499972905472315i
请帮助...谢谢!