[R] Matrix multiplication

annek annek at ifm.liu.se
Wed Dec 12 08:19:09 CET 2012


Hi, 
I have a transition matrix T for which I want to find the steady state matrix for. This could be approximated by taking T^n , for large n. 

T= [ 0.8797   0.0382   0.0527   0.0008
      0.0212    0.8002   0.0041   0.0143
      0.0981    0.0273   0.8802   0.0527
      0.0010    0.1343   0.0630   0.9322]

According to a text book I have T^200 should have reached the steady state L

L =[0.17458813   0.17458813   0.17458813   0.17458813
      0.05731902   0.05731902   0.05731902   0.05731902
      0.35028624   0.35028624   0.35028624   0.35028624
      0.44160126   0.44160126   0.44160126   0.44160126]

I am addressing the problem using a for loop doing matrix multiplication (guess there might be better ways, please suggest) and find a steady state matrix after n=30. But if I run the code with n=100 or more I get "Inf" for all entities in L. Does anyone know why is that?

The code I use look like this
#------------------------------------
rep<-20

T <- Ttest
for(i in 1:rep){
 print(i)
 T<-T%*%Ttest
 Ttest<-T
}
L<-T
print(L)
#----------------------------------


More information about the R-help mailing list