for循环中矩阵的特征值 [英] Eigenvalues for matrices in a for loop
问题描述
我需要计算一系列矩阵的特征值,然后将它们保存在单独的文件中.我的数据有5列和10,000行.我使用以下功能:
I need to calculate eigenvalues of a series of matrices and then save them in a separate file. My data has 5 columns and 10,000 rows. I use the following functions:
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列的数据集.这给了我以下结果:
As an example I have used a data set with 10 rows and 5 columns. This gives me the following results:
$`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
我有三个问题,我将不胜感激:
I have three questions and I would really appreciate any help:
-
我想将结果保存在连续的行中,例如:
I want to save the results in consecutive rows, such as:
Eigenvalue(1) Eigenvalue(3) Eigenvalue(5) Eigenvalue(7) Eigenvalue(9)
Eigenvalue(2) Eigenvalue(4) Eigenvalue(6) Eigenvalue(8) Eigenvalue(10)
有什么想法吗?
此外,我不理解输出中的特征值.他们不是数字.例如,其中之一是2.362320e + 02 + 0.000000e + 00i.我的第一个想法是,这是一个5x5矩阵的五个行列式的总和.但是,"2.362320e + 02 + 0.000000e + 00i"似乎只有四个数字.有什么想法吗? eigen
()函数不计算特征值的最终值吗?
Also, I don't understand the eigenvalues in the output. They are not numbers. For example, one of them is 2.362320e+02+0.000000e+00i. My first though was that this is the sum of five determinants for a 5x5 matrix. However, "2.362320e+02+0.000000e+00i" seems to only have four numbers in it. Any thoughts? Doesn't eigen
() function calculate the final values of eigenvalues?
如何将结果保存在Excel文件中?我使用了以下代码
how can I save my outcome on an Excel file? I have used the following codes
但是,我从当前代码中得到的结果是:
However, the result I get from the current codes are:
> class(R)
[1] "matrix"
> print(R)
values vectors
E Complex,5 NULL
E Complex,5 NULL
推荐答案
我认为,您可以通过以下代码轻松获取值:
I think, you can easily get values by the following code:
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
保存到文件
and then use the answer of this question, to save R
into a file
这篇关于for循环中矩阵的特征值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!