0

I have to calculate the eigenvalues and eigenvectors, but I always have this warning. I hope someone can tell me what's going on.

#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
  • It means it calculates only the eigen value of the first element which is `K` in this setting, run `eigen(K,M)` and `eigen(K)` . You will see that it will give the same output. – maydin Aug 18 '19 at 21:01

1 Answers1

2

This error means that the variable symmetric (probably internal to the eigen function) is evaluating to a logical vector with length greater than one. When this happens in the condition of an if statement, only the first element is used.

The documentation leads me to think that you want to pass each matrix to the function separately.

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

Use ?eigen to view the help for this function, which suggests it's only expecting one argument to be a matrix.

EDIT: Below you can find the code that defines the eigen() function. In the RStudio IDE, you can hover over a function and press F2 to get the code for the function. Based on this, when you give M as the second argument to the eigen() function, it is interpreting it as eigen(x = K, symmetric = M). It expects for symmetric to be TRUE, FALSE or missing, but instead it is getting a matrix. When it gets to the line where symmetric is used as the condition for an if statement, it throws this warning.

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]))
}
AColeman
  • 485
  • 3
  • 8