【发布时间】:2016-10-17 05:24:44
【问题描述】:
我正在制作一个广泛使用特征值和特征向量的程序。在测试程序时,我遇到了两个具有相同特征值的特征向量不是完全正交的情况。我知道在退化特征向量的情况下,解决方案不是唯一的,并且不能保证求解例程产生某个向量,因为退化特征向量的线性组合仍然是具有相同特征值的特征向量。但是,我确实希望它们两个是正交的。
这是一个错误吗? dgeev 产生的所有特征向量都应该是正交的吗?是否有另一个例程总是会打印出正交向量?
这是一个 C 语言的测试用例:
#include <stdio.h>
void ctofortran(double *matrix,double *fortranMatrix,int numberOfRows,int numberOfColumns)
{
/******************************************************************/
/* This function converts a row-major C matrix into a column-major*/
/* fortran "array". */
/******************************************************************/
int columnNumber,rowNumber;
for (columnNumber = 0;columnNumber<numberOfColumns ;columnNumber++ )
{
for (rowNumber = 0;rowNumber<numberOfRows ;rowNumber++ )
{
fortranMatrix[rowNumber+numberOfRows*columnNumber] = *(matrix + columnNumber+numberOfColumns*rowNumber);
}
}
}
int main(int argc, char **argv)
{
double matrix[] = {4, -1, 0, -1, 0, 0, 0, 0,
-1, 4, -1, 0, 0, 0, 0, 0,
0, -1, 4, 0, -1, 0, 0, 0,
-1, 0, 0, 4, 0, -1, 0, 0,
0, 0, -1, 0, 4, 0, 0, -1,
0, 0, 0, -1, 0, 4, -1, 0,
0, 0, 0, 0, 0, -1, 4, -1,
0, 0, 0, 0, -1, 0, -1, 4 };
int rows = 8, columns = 8;
double *fortranmatrix = malloc(rows*columns*sizeof(double));
ctofortran(matrix,fortranmatrix,rows,columns);
char jobvl ='v';
char jobvr = 'n';
//This symbolizes that the left eigenvectors will be found
double *realEigenValues,*imaginaryEigenValues;
realEigenValues = malloc(rows*sizeof(double));
imaginaryEigenValues = malloc(rows*sizeof(double));
double *leftEigenVectors = malloc(rows*columns*sizeof(double));
int lwork = rows * 4;
double *work = malloc(lwork*sizeof(double));
//This allocates workspace to be used by dgeev. The recomended space is 4 times the dimension
int info = 0;//After dgeev info = 0 if the calculation went correctly
dgeev_(&jobvl,&jobvr,&rows,fortranmatrix,&rows,realEigenValues,imaginaryEigenValues,leftEigenVectors,&rows,NULL,&rows,work,&lwork,&info);
int index;
for(index = 0;index<rows;index++)
printf("Eigenvalue %d %g + %g * i\n",index,*(realEigenValues+index), *(imaginaryEigenValues+index));
int v1 = 1, v6 = 6;
double sum = 0;
printf("\nv1\tv6\n");
for(index = 0;index<rows;index++)
{
printf("%g\t%g\n",*(leftEigenVectors+v1*rows+index),*(leftEigenVectors+v6*rows+index));
sum += *(leftEigenVectors+v1*rows+index) * *(leftEigenVectors+v6*rows+index);
}
printf("\n Dot product between v1 and v6 %g\n",sum);
return 0;
}
这是输出:
Eigenvalue 0 2 + 0 * i
Eigenvalue 1 2.58579 + 0 * i
Eigenvalue 2 4 + 0 * i
Eigenvalue 3 6 + 0 * i
Eigenvalue 4 5.41421 + 0 * i
Eigenvalue 5 5.41421 + 0 * i
Eigenvalue 6 2.58579 + 0 * i
Eigenvalue 7 4 + 0 * i
v1 v6
-0.499878 0
-0.345657 0.353553
0.0110458 0.5
-0.361278 -0.353553
0.361278 0.353553
-0.0110458 -0.5
0.345657 -0.353553
0.499878 -9.88042e-16
Dot product between v1 and v6 0.0220917
v6 对我来说看起来更“正常”。
*这个矩阵是对称的,但并不总是这样。
【问题讨论】:
-
我在这里只是从臀部拍摄(我从未使用过 lapack),但这对我来说似乎是一个浮点舍入问题。请参阅stackoverflow.com/questions/588004/… 了解更多信息。
-
相关? icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2&t=1769我尝试在 Julia 中使用 LAPACK.geev!() 处理相同的矩阵,它为退化对提供了非正交特征向量。
-
@roygvib,是的,这绝对有帮助。我切换到 DSYEVD 并打印出正交特征向量(但它确实需要一个对称矩阵)。我将研究非对称矩阵是否可能,因为我认为它是可能的,但也许这是错误的。
标签: c linear-algebra lapack