[R] recursive matrix multiplication question

Ivan Kautter ivankautter at hotmail.com
Sun Mar 14 00:38:34 CET 2004


List serv subscribers,

I am wondering if there is an efficient means of doing recursive matrix 
multiplication in R.  My data resides in a 4 X 2541 matrix from which I need 
to extract 2541 2X2 matrices based on each row.  If I attempt something like 
this:

function(AO)
{A<-AO
{for(t in 1:4)
A[t+1]<-matrix(h0m[t,1:4],nrow=2,ncol=2,byrow=FALSE)%*%matrix(h0m[t+1,1:4],nrow=2,ncol=2,byrow=FALSE)
}
}

I get this type of error:

1: number of items to replace is not a multiple of replacement length
2: number of items to replace is not a multiple of replacement length
3: number of items to replace is not a multiple of replacement length
4: number of items to replace is not a multiple of replacement length

I believe I understand the error here in that I am attempting to add more 
elements to an object that is only a 2x2 matrix.  So is there some way to 
just update the value of the matrix recursively?  If you are asking yourself 
why I am bothering to do this if I mean to multiple only 4 matrices, I 
actually intend to multiple up to all 2541 of them, which seems no small 
task.  Ultimately, I would like to define the time period over which I am 
multiplyig these essentially time-dependent matrices and obtain the 
eigenvalues of the final matrix product.

If anyone can offer any assistance, I would greatly appreciate it.  Thanks.

Ivan Kautter





More information about the R-help mailing list