Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A demo R script of [the paper EIGENVECTORS FROM EIGENVALUES](, modified from [Yu-Chen Shu]( rewritten in R.
# Generate random matrix with dim = N
N <- 3
A <- matrix(runif(N*N), N, N, byrow=TRUE)
A <- A+t(A)
# Setting up eigenvalues lambda, true eigenvector V and derived eigenvector U
ev <- eigen(A)
(lambda <- ev$values)
(V <- ev$vectors)
U <- matrix(0L, N, N)
# Calculate from lemma 2 in
for (i in 1:N) {
lambda_D <- lambda; lambda_D[i] <- NA; lambda_D <- lambda_D[!]
denominator <- prod(lambda[i]-lambda_D)
for (j in 1:N) {
M <- A; M[,j] = M[j,] <- NA; M <- matrix(M[!], N-1, N-1)
lambda_M <- eigen(M)$values
fraction <- prod(lambda[i]-lambda_M)
U[j,i] <- fraction/denominator
# Check the infinity norm of DIFF(U, V^2) shows that they are close enough
norm(U - V*V, type="I")

This comment has been minimized.

Copy link

@GreenEric GreenEric commented Nov 17, 2019

Thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.