A <- matrix(c(0, 30, 60, 10, 0.25, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0.35, 0), nr = 4, byrow = TRUE)
A
## [,1] [,2] [,3] [,4]
## [1,] 0.00 30.0 60.00 10
## [2,] 0.25 0.0 0.00 0
## [3,] 0.00 0.5 0.00 0
## [4,] 0.00 0.0 0.35 0
nt <- matrix(c(500, 100, 300, 50), ncol = 1)
nt
## [,1]
## [1,] 500
## [2,] 100
## [3,] 300
## [4,] 50
nt1= A %*% nt
nt1
## [,1]
## [1,] 21500
## [2,] 125
## [3,] 50
## [4,] 105
years=8
n.projections <- matrix(0, nrow = nrow(A), ncol = years + 1)
n.projections
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## [1,] 0 0 0 0 0 0 0 0 0
## [2,] 0 0 0 0 0 0 0 0 0
## [3,] 0 0 0 0 0 0 0 0 0
## [4,] 0 0 0 0 0 0 0 0 0
n.projections[, 1] <- nt
n.projections
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## [1,] 500 0 0 0 0 0 0 0 0
## [2,] 100 0 0 0 0 0 0 0 0
## [3,] 300 0 0 0 0 0 0 0 0
## [4,] 50 0 0 0 0 0 0 0 0
for (i in 1:years) n.projections[, i + 1] <- A %*% n.projections[,i]
n.projections
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 500 21500 7800.0 165175.000 219968.750 1306718.75 2891990.625
## [2,] 100 125 5375.0 1950.000 41293.750 54992.19 326679.688
## [3,] 300 50 62.5 2687.500 975.000 20646.88 27496.094
## [4,] 50 105 17.5 21.875 940.625 341.25 7226.406
## [,8] [,9]
## [1,] 11522420.312 31586556.64
## [2,] 722997.656 2880605.08
## [3,] 163339.844 361498.83
## [4,] 9623.633 57168.95
matplot(0:years, t(n.projections), type = "l", lty = 1:3,col = 1, ylab = "Stage Abundance", xlab = "Year")
legend("topleft", legend = c("Semilla", "Adulto pequeño", "Adulto mediano", "Adulto grande"),lty = 1:4, col = 1, bty = "n")
