for 循环中矩阵的特征值

Eigenvalues for matrices in a for loop

我需要计算一系列矩阵的特征值,然后将它们保存在一个单独的文件中。我的数据有 5 列和 10,000 行。我使用以下功能:

        R<-NULL

    A <- setwd("c:/location of the file on this computer")
    for(i in 0:1){
      X<-read.table(file="Example.prn", skip=i*5, nrow=5)
      M <- as.matrix(X)
      E=eigen(M, only.values = TRUE)
      R<-rbind(R,E)}
      print(E)
    }

作为示例,我使用了一个包含 10 行和 5 列的数据集。这给了我以下结果:

$`values`
[1]  1.350000e+02+0.000e+00i -4.000000e+00+0.000e+00i  4.365884e-15+2.395e-15i  4.365884e-15-2.395e-15i
[5]  8.643810e-16+0.000e+00i

$vectors
NULL

$`values`
[1]  2.362320e+02+0.000000e+00i -4.960046e+01+1.258757e+01i -4.960046e+01-1.258757e+01i  9.689475e-01+0.000000e+00i
[5]  1.104994e-14+0.000000e+00i

$vectors
NULL

我有三个问题,非常感谢您的帮助:

  1. 我想把结果保存在连续的行中,比如:

    Eigenvalue(1) Eigenvalue(3) Eigenvalue(5) Eigenvalue(7) Eigenvalue(9)
    Eigenvalue(2) Eigenvalue(4) Eigenvalue(6) Eigenvalue(8) Eigenvalue(10)
    

    有什么想法吗?

  2. 此外,我不理解输出中的特征值。它们不是数字。比如其中一个是2.362320e+02+0.000000e+00i。我的第一个想法是,这是 5x5 矩阵的五个行列式的总和。但是,“2.362320e+02+0.000000e+00i”里面好像只有四个数字。有什么想法吗? eigen() 函数不是计算特征值的最终值吗?

  3. 如何将结果保存在 Excel 文件中?我使用了以下代码

然而,我从当前代码得到的结果是:

> class(R)
[1] "matrix"
> print(R)
  values    vectors   
E Complex,5 NULL
E Complex,5 NULL

我认为,您可以通过以下代码轻松获取值:

R<-NULL

A <- setwd("c:/location of the file on this computer")
for(i in 0:1){
  X<-read.table(file="Example.prn", skip=i*5, nrow=5)
  M <- as.matrix(X)
  E=eigen(M, only.values = TRUE)
  R<-rbind(R,E$values)}

}

然后使用的答案将R保存到文件