This is the code I'm trying to run and it worked in the past but now I am getting an error on the "Nt[ ,1] <- N0" saying, number of items to replace is not a multiple of replacement length. I don't know how to resolve this.
'''r
L <- matrix(c(0, 2.5, 5.0, 5.0,
0.20, 0, 0, 0,
0, 0.35, 0, 0,
0, 0, 0.45, 0,
0,0,0,0.25),
byrow=T, nrow=5, ncol=4)
L
N0 <- matrix(c(100, 30, 20, 10), byrow=T, nrow=4, ncol=1)
N0
N1 <- L%*%N0
N1
n.years <- 25
Nt <- matrix(NA, nrow=nrow(L), ncol=n.years)
Nt
Nt[ ,1] <- N0
Nt
for(t in 2:n.years){
Nt[ ,t] <- L%*%Nt[ ,t-1]
}
print(round(Nt[ ,1:25], digits=0))
Nproj <- apply(Nt, 2, sum)
plot(1:length(Nproj), Nproj, ylim=c(100,300), ylab="N", xlab="Years", type="l", lwd=2)
plot(1:n.years, Nt[1,], ylim=c(0,300), ylab="N", xlab="Years", type="l", col=1, lwd=2)
lines(1:n.years, Nt[2,], type="l", col=2, lwd=2)
lines(1:n.years, Nt[3,], type="l", col=3, lwd=2)
lines(1:n.years, Nt[4,], type="l", col=4, lwd=2)
lines(1:n.years, Nt[5,], type="1", col=5, lwd=2)
L_eigen <- eigen(L)
L_eigen
lambda <- Re(L_eigen$values[1])
lambda