matrix program
On Wed, 9 Mar 2005 15:24:45 -0400 Owen Buchner wrote:
I'm attempting to produce a program in which i can multiply a 4x4 matrix by a vector. I would like to have this occur 30 times with the product of the matrix and vector replace the original vector, kind of like population growth. I'm having difficulties with the programing aspect and continuously get errors from R. I would appreciate any help.
Are you looking for something like this toy example?
Generate a matrix mm and a vector xx:
R> mm <- matrix(rep(1, 4), ncol = 2)
R> xx <- rep(1, 2)
R> mm
[,1] [,2]
[1,] 1 1
[2,] 1 1
R> xx
[1] 1 1
And then pre-multiply 10 times by mm:
R> for(i in 1:10) xx <- mm %*% xx
R> xx
[,1]
[1,] 1024
[2,] 1024
which in this case is of course just 2^10.
hth,
Z
Owen Buchner