I' trying to get the largest eigenvalue of a fully-connected right stochastic matrix in R & MATLAB. From this link: http://en.wikipedia.org/wiki/Stochastic_matrix I understand that the largest eigenvalue will be 1. For example, we can see the eigenvalues are "1, 0" after running the following code in R:
> eigen(matrix(rep(0.5,4),ncol=2))
$values
[1] 1 0
$vectors
[,1] [,2]
[1,] 0.707107 -0.707107
[2,] 0.707107 0.707107
But recently, I found a very interested result if I try to get the largest eigenvalue of the following stochastic matrix:
> m = matrix(c(0.5, 0.995, 0.5, 0.005),ncol = 2 ,nrow=2);
> eigen(m)$value
[1] 1.000 -0.495
> eigen(m)$value[1] == 1
[1] FALSE
Notice that it show "FALSE". That's weird! It should be equal to 1, right? There should have some computation errors. I also tried this matrix in MATLAB and still got the same result. So far, I can only round it up to 1. Any idea about how to fix it?
Thank you,
Ken