Skip to content
Back to formatted view

Raw Message

Message-ID: <20050309204309.7facbd13.Achim.Zeileis@wu-wien.ac.at>
Date: 2005-03-09T19:43:09Z
From: Achim Zeileis
Subject: matrix program
In-Reply-To: <1110396285.422f4d7d708fa@my1.dal.ca>

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
>