首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lapack dgeev简并特征向量非正交

Lapack dgeev简并特征向量非正交
EN

Stack Overflow用户
提问于 2016-06-16 06:03:15
回答 1查看 481关注 0票数 1

我正在编写一个广泛使用特征值和特征向量的程序。在测试程序时,我遇到了两个具有相同特征值的特征向量不完全正交的情况。我知道在退化特征向量的情况下,解不是唯一的,并且求解例程不能保证产生特定的向量,因为退化特征向量的线性组合仍然是具有相同特征值的特征向量。然而,我确实希望他们两个是正交的。

这是一个bug吗?dgeev产生的所有特征向量都应该是正交的吗?有没有另一个例程总是打印出正交向量?

下面是一个C语言的测试用例:

代码语言:javascript
复制
#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;

}

下面是输出:

代码语言:javascript
复制
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看起来更“正常”。

*这个矩阵是对称的,但不会总是对称的。

EN

回答 1

Stack Overflow用户

发布于 2016-06-16 06:54:16

尝试使用%lf打印,如下所示:

代码语言:javascript
复制
printf("\n Dot product between v1 and v6 %lf\n",sum);

就像这里描述的那样:Scanf/Printf double variable C

如果这还不起作用,那么我猜这是一个浮点问题(因为他们的点积很小)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37846564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档