To choose the largest eigenvalue that's not complex, you can do:
eigenvalues = eigen(x)$values
max(Re(eigenvalues[abs(Im(eigenvalues)) < 1e-6])) # you have to choose the precision you like here
Pregunta
I am a newby in R and I have a square matrix 100x100. I want to find the biggest eigenvalue of this matrix. I tried
is.indefinite(x)
but it writes
is.indefinite(x) : argument x is not a symmetric matrix
Does anyone know a function to find eigenvalues, or better the biggest eigenvalue in R?
Solución 2
To choose the largest eigenvalue that's not complex, you can do:
eigenvalues = eigen(x)$values
max(Re(eigenvalues[abs(Im(eigenvalues)) < 1e-6])) # you have to choose the precision you like here
Otros consejos
Apparently nobody reads the docs:
The spectral decomposition of
x
is returned as components of a list with components
values
- a vector containing the
p
eigenvalues ofx
, sorted in decreasing order, according toMod(values)
in the asymmetric case when they might be complex (even for real matrices). For real asymmetric matrices the vector will be complex only if complex conjugate pairs of eigenvalues are detected.
So the solution (ignoring complex eigenvalues) is
eigen(x)$values[1]
Take a look at eigen
function. If your matrix is x
you can do:
max(eigen(x)$values)
Handling all of the eigen values as complex and then calculating the distances to origin would help to find the biggest one.
You can do,
eigenvalues = eigen(x)
max(abs(eigenvalues$values))
If you want to take eigenvector of maximum eigenvalue check this https://stat.ethz.ch/pipermail/r-help/2012-April/311192.html