for循环中矩阵的特征值

问题描述 投票:0回答:1

我需要计算一系列矩阵的特征值,然后将它们保存在一个单独的文件中。我的数据有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
for-loop output eigenvalue
1个回答
0
投票

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

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)}

}

然后使用this question的答案,将R保存到文件中

© www.soinside.com 2019 - 2024. All rights reserved.