Re: [R] matrix program

From: Achim Zeileis <Achim.Zeileis_at_wu-wien.ac.at>
Date: Thu 10 Mar 2005 - 06:43:09 EST

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
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Mar 10 06:50:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:42 EST