GSL错误的特征值

时间:2017-05-04 16:19:02

标签: gsl eigenvalue

我获得的特征值对于GSL(Gnu科学图书馆)和Matlab是不同的。有人能给我一个提示我做错了吗? :

#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_permutation.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_blas.h>

int main(int argc,char** argv)
{
double data[] = { -1.0, 1.0, -1.0, 1.0,
                  -8.0, 4.0, -2.0, 1.0,
                   27.0, 9.0, 3.0, 1.0,
                   64.0, 16.0, 4.0, 1.0 };

gsl_matrix_view m
    = gsl_matrix_view_array (data, 4, 4);

gsl_vector_complex *eval = gsl_vector_complex_alloc (4);
gsl_matrix_complex *evec = gsl_matrix_complex_alloc (4, 4);
gsl_eigen_nonsymmv_workspace * w =gsl_eigen_nonsymmv_alloc (4);
gsl_eigen_nonsymmv (&m.matrix, eval, evec, w);
gsl_eigen_nonsymmv_free (w);
int i, j;
for (i = 0; i < 4; i++)
{
    gsl_complex eval_i
       = gsl_vector_complex_get (eval, i);
    gsl_vector_complex_view evec_i
       = gsl_matrix_complex_column (evec, i);

    printf ("eigenvalue = %g + %gi\n",
            GSL_REAL(eval_i), GSL_IMAG(eval_i));
    printf ("eigenvector = \n");
    for (j = 0; j < 4; ++j)
      {
        gsl_complex z =
          gsl_vector_complex_get(&evec_i.vector, j);
        printf("%g + %gi\n", GSL_REAL(z), GSL_IMAG(z));
      }
  }
}

根据GSL得到的特征值/特征值是:

 eigenvalue = -6.41391 + 0i
 eigenvector = 
 0.0998822 + 0i
 0.111251 + 0i
 -0.292501 + 0i
 -0.944505 + 0i
 eigenvalue = 5.54555 + 3.08545i
 eigenvector = 
 0.0430757 + 0.00968662i
 -0.0709124 + 0.138917i
 0.516595 + -0.0160059i
 0.839574 + 0.0413888i
 eigenvalue = 5.54555 + -3.08545i
 eigenvector = 
 0.0430757 + -0.00968662i
-0.0709124 + -0.138917i
 0.516595 + 0.0160059i
 0.839574 + -0.0413888i
 eigenvalue = 2.3228 + 0i
 eigenvector = 
 -0.144933 + 0i
 0.356601 + 0i
 0.919369 + 0i
 0.0811836 + 0i

但MATLAB返回以下特征值:

 -5.4485 + 0.0000i
  5.5948 + 3.5267i
  5.5948 - 3.5267i
  1.2588 + 0.0000i

我会做错吗?任何提示都表示赞赏。

0 个答案:

没有答案