Is this what you want?
Your code
#the data
A <- c(0,0,100, 0.4,0,0, 0,0.7,0)
#create a matrix from the data
L <- matrix(A, nrow=3, byrow=T)
#check out the matrix
L
#the starting population
n_0 <- c(1000, 400, 100)
#the next generation
#n_1 <- L %*% n_0
#check it out
#n_1
#run another generation
#n_2 <- L %*% n_1
#check it out
#n_2
my code:
pops <- list()
pops[[1]] <- n_0
for(i in 2: 20){ # gives 19 generations
pops[[i]] <- L %*% pops[[i-1]] # assign your matrix mult to a list slot
}
pops[[20]] # the 19th generation (because the first slot is the 0
generation)
HTH
Alan
--------------------------------------------------
Email: [email protected]
Mobile: +41794385586
Skype: aghaynes
On 29 November 2012 17:07, Jeffrey Stratford
<[email protected]>wrote:
> Hi everyone,
>
> I have a two part population lab in my Ecology course. The first part was
> showing exponential and logistic growth. For the second section, I would
> like to introduce them to Leslie/Lefkovitch models. I'm able to multiply
> the matrix and the age classes step by step but I would like to have them
> run projections for as many generations as they choose and show the
> population structure by plotting the number in each age class over time.
>
> I know software programs like Populus do this but I would like to have them
> (and myself) learn the programming.
>
> Here's what I have so far:
>
> #the data
> A <- c(0,0,100, 0.4,0,0, 0,0.7,0)
> #create a matrix from the data
> L <- matrix(A, nrow=3, byrow=T)
> #check out the matrix
> L
> #the starting population
> n_0 <- c(1000, 400, 100)
> #the next generation
> n_1 <- L %*% n_0
> #check it out
> n_1
> #run another generation
> n_2 <- L %*% n_1
> #check it out
> n_2
>
>
> Many thanks,
>
> Jeff
> --
> ********************************************************
> Jeffrey A. Stratford, PhD
> Department of Biology and Health Sciences
> Wilkes University, PA 18766 USA
> 570-332-2942
> http://web.wilkes.edu/jeffrey.stratford/
> ********************************************************
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
[[alternative HTML version deleted]]
_______________________________________________
R-sig-ecology mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology