【问题标题】:Warning while I am calculating eigenvalues计算特征值时发出警告
【发布时间】:2019-08-18 20:54:43
【问题描述】:

我必须计算特征值和特征向量,但我总是有这个警告。我希望有人能告诉我发生了什么事。

#masa en kg
m1=559.3e-3
m2=419.4e-3
m3=m2
m4=m2
m5=m2
m6=m2
m7=m2
m8=m2
#rigidez en N/m
k=56.7e3
#matrices de masa y rigidez
M=matrix(c(m1,0,0,0,0,0,0,0,0,m2,0,0,0,0,0,0,0,0,m3,0,0,0,0,0,0,0,0,m4,0,0,0,0,0,0,0,0,m5,0,0,0,0,0,0,0,0,m6,0,0,0,0,0,0,0,0,m7,0,0,0,0,0,0,0,0,m8), 8, 8, byrow=TRUE)
K=matrix(c(k,-k,0,0,0,0,0,0,-k,2*k,-k,0,0,0,0,0,0,-k,2*k,-k,0,0,0,0,0,0,-k,2*k,-k,0,0,0,0,0,0,-k,2*k,-k,0,0,0,0,0,0,-k,2*k,-k,0,0,0,0,0,0,-k,2*k,-k,0,0,0,0,0,0,-k,k), 8, 8, byrow=TRUE)
#calculo valores y vectores propios
a=eigen(K,M)

>Warning message:
In if (symmetric) { :
the condition has length > 1 and only the first element will be used

【问题讨论】:

  • 这意味着它只计算第一个元素的特征值 K 在这个设置中,运行 eigen(K,M)eigen(K) 。你会看到它会给出相同的输出。

标签: r warnings linear-algebra eigenvalue symmetric


【解决方案1】:

此错误意味着变量 symmetric(可能是 eigen 函数的内部变量)正在评估长度大于 1 的逻辑向量。当这种情况发生在 if 语句的条件下时,只使用第一个元素。

文档让我认为您想将每个矩阵分别传递给函数。

a <- eigen(K)
b <- eigen(M)

使用?eigen 查看此函数的帮助,这表明它只期望一个参数为矩阵。

编辑:您可以在下面找到定义eigen() 函数的代码。在 RStudio IDE 中,您可以将鼠标悬停在函数上并按 F2 以获取函数的代码。基于此,当您将M 作为eigen() 函数的第二个参数时,它会将其解释为eigen(x = K, symmetric = M)。它期望symmetricTRUEFALSE 或缺失,但它却得到一个矩阵。当它到达symmetric 用作if 语句条件的行时,它会抛出此警告。

function (x, symmetric, only.values = FALSE, EISPACK = FALSE) 
{
  x <- unname(as.matrix(x))
  n <- nrow(x)
  if (!n) 
    stop("0 x 0 matrix")
  if (n != ncol(x)) 
    stop("non-square matrix in 'eigen'")
  n <- as.integer(n)
  if (is.na(n)) 
    stop("invalid nrow(x)")
  complex.x <- is.complex(x)
  if (!all(is.finite(x))) 
    stop("infinite or missing values in 'x'")
  if (missing(symmetric)) 
    symmetric <- isSymmetric.matrix(x)
  if (symmetric) {                    # Here is the line generating the error
    z <- if (!complex.x) 
      .Internal(La_rs(x, only.values))
    else .Internal(La_rs_cmplx(x, only.values))
    ord <- rev(seq_along(z$values))
  }
  else {
    z <- if (!complex.x) 
      .Internal(La_rg(x, only.values))
    else .Internal(La_rg_cmplx(x, only.values))
    ord <- sort.list(Mod(z$values), decreasing = TRUE)
  }
  if (only.values) 
    list(values = z$values[ord], vectors = NULL)
  else structure(class = "eigen", list(values = z$values[ord], 
    vectors = z$vectors[, ord, drop = FALSE]))
}

【讨论】:

    猜你喜欢
    • 2012-08-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    相关资源
    最近更新 更多