为什么java(jama/math3)和matlab/python计算的特征值不同?

w8biq8rn  于 2021-07-11  发布在  Java
关注(0)|答案(0)|浏览(438)

有一些需要计算给定矩阵的特征值,但是我发现在matlab和java中给出了不同的结果。给定matlab中的矩阵:

x=[[0.9991064766057767, 1.3003274547457159E8, 8.2589524321425552E16,9.065301406782726E25, 3.1791759769979634E34, 5.145828201380777E42];[5.905543519041531E-4,6.52297956260086E7,1.1242553048989866E16,2.9885609033349647E24,8.710071169857434E32,4.288190167817314E41];[1.8659562881188536E-4,2095424.7256421563,9.512929502991425E14,1.6603116129638694E23,0,0];[1.0062771059108464E-4, 271629.131101761, 8.648117729992205E13, 0, 0, 0];[1.3392896733345797E-5,38804.161585965856,0,0,0,0]; [2.3528061828850723E-6,0,0,0,0,0]]

输出v矩阵(使用函数eigs()):

0.9993 + 0.0000i   0.9993 + 0.0000i  -0.9987 + 0.0000i  -0.9987 + 0.0000i   0.9998 + 0.0000i   0.9998 + 0.0000i
   0.0387 + 0.0000i   0.0387 + 0.0000i  -0.0509 + 0.0000i  -0.0510 + 0.0000i  -0.0211 + 0.0000i  -0.0211 - 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0077 + 0.0000i   0.0077 + 0.0000i   0.0000 + 0.0000i   0.0000 - 0.0000i
   0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 - 0.0000i
   0.0000 + 0.0000i  -0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 + 0.0000i  -0.0000 + 0.0000i  -0.0000 - 0.0000i
   0.0000 + 0.0000i  -0.0000 + 0.0000i  -0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 - 0.0000i   0.0000 + 0.0000i

d矩阵:1.0e+18*

7.7371 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i  -7.7371 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   3.7897 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i  -3.7888 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 3.7358i   0.0000 + 0.0000i
   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 + 0.0000i   0.0000 - 3.7358i

在java中:定义相同的测试矩阵:

double[][] test = new double[6][6];
    test[0][0] = 0.9991064766057767;
    test[0][1] = 1.3003274547457159E8;
    test[0][2] = 8.2589524321425552E16;
    test[0][3] = 9.065301406782726E25;
    test[0][4] = 3.1791759769979634E34;
    test[0][5] = 5.145828201380777E42;
    test[1][0] = 5.905543519041531E-4;
    test[1][1] = 6.52297956260086E7;
    test[1][2] = 1.1242553048989866E16;
    test[1][3] = 2.9885609033349647E24;
    test[1][4] = 8.710071169857434E32;
    test[1][5] = 4.288190167817314E41;
    test[2][0] = 1.8659562881188536E-4;
    test[2][1] = 2095424.7256421563;
    test[2][2] = 9.512929502991425E14;
    test[2][3] = 1.6603116129638694E23;
    test[3][0] = 1.0062771059108464E-4;
    test[3][1] = 271629.131101761;
    test[3][2] = 8.648117729992205E13;
    test[4][0] = 1.3392896733345797E-5;
    test[4][1] = 38804.161585965856;
    test[5][0] = 2.3528061828850723E-6;
    RealMatrix matrix = new Array2DRowRealMatrix(test);
    EigenDecomposition eigen = new EigenDecomposition(matrix);

我得到d矩阵:

Array2DRowRealMatrix{{-151115727451828650000000.0,151115727451828650000000.0,0.0,0.0,0.0,0.0},{-151115727451828650000000.0,-151115727451828650000000.0,0.0,0.0,0.0,0.0},{0.0,0.0,121490934714923220000000.0,835322221745495900000000.0,0.0,0.0},{0.0,0.0,-835322221745495900000000.0,121490934714923220000000.0,0.0,0.0},{0.0,0.0,0.0,0.0,-24594465620584907000000.0,24594465620584907000000.0},{0.0,0.0,0.0,0.0,-24594465620584907000000.0,-24594465620584907000000.0}}

为什么结果差别很大(一个是e18级,另一个是e23级)?我试过python,它们输出的结果与matlab中的结果相同。
当我尝试一些整数矩阵时,java和matlab可以输出相同的结果。
有什么我做得不对的吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题