Skip to content

Instantly share code, notes, and snippets.

@gbersac
Created April 15, 2015 12:12
Show Gist options
  • Save gbersac/4335bc17ca38fe07f7b3 to your computer and use it in GitHub Desktop.
Save gbersac/4335bc17ca38fe07f7b3 to your computer and use it in GitHub Desktop.
Eigen vector implementation in R
> Origin
[,1] [,2] [,3] [,4]
[1,] 52 30 49 28
[2,] 30 50 8 44
[3,] 49 8 46 16
[4,] 28 44 16 22
> round(X,5)
[,1] [,2] [,3] [,4]
[1,] 265.2557 0.0000 0.00000 0.00000
[2,] 0.0000 104.8846 0.00000 0.00000
[3,] 0.0000 0.0000 -23.08226 0.00000
[4,] 0.0000 0.0000 0.00000 -7.05809
> round(pQ,5)
[,1] [,2] [,3] [,4]
[1,] 0.60946 -0.29992 -0.09988 -0.72707
[2,] 0.48785 0.65200 0.57725 0.06069
[3,] 0.46658 -0.60196 0.22156 0.60898
[4,] 0.41577 0.35013 -0.77956 0.31117
# some symmetric matrix
Origin <- matrix(c(52, 30, 49, 28, 30, 50, 8, 44, 49, 8, 46, 16, 28, 44, 16, 22), 4, 4)
A <- Origin + t(Origin);
# initialize
X <- A;
pQ <- diag(1, dim(A)[1]);
# iterate
for(i in 1:30){
d <- qr(X);
Q <- qr.Q(d);
pQ <- pQ %*% Q;
X <- qr.R(d) %*% Q;
}
Origin
round(X,5)
round(pQ,5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment