Untitled
unknown
plain_text
a year ago
2.5 kB
4
Indexable
#LM for turtles
L_turtles <- matrix(c(
0, 0, 0, 127, 4, 80, 0,
0.6747, 0, 0, 0, 0, 0, 0,
0, 0.737, 0, 0, 0, 0, 0,
0, 0.0486, 0.661, 0, 0, 0, 0,
0, 0, 0.0147, 0.6907, 0, 0, 0,
0, 0, 0, 0.0518, 0.8091, 0, 0,
0, 0, 0, 0, 0.8091, 0.8089, 0
), nrow = 7, byrow = TRUE)
#LM for sharks
L_sharks <- matrix(c(
0, 0.1, 25,
0.3, 0, 0,
0, 0.22, 0.95
), nrow = 3, byrow = TRUE)
#Predation rate parameters tests
a <- 0.01
b <- 0.01
#Initial pop sizes
initial_sea_turtle_pop <- c(300, 200, 150, 100, 50, 30, 20)
initial_tiger_shark_pop <- c(10, 5, 2)
# Calculate dynamic fecundity for each class
calculate_fecundity <- function(L_turtles, L_sharks, a, b, X, Y) {
# Extract baseline fecundity values for turtles and sharks
fx <- L_turtles[1, ]
fy <- L_sharks[1, ]
#vectors for dynamic fecundity values
FX <- numeric(length(fx))
FY <- numeric(length(fy))
#Calculate dynamic fecundity for turtles
for (i in 1:length(fx)) {
FX[i] <- fx[i] * exp(-a * Y[3]) # Y[3] is the number of adult predators (tiger sharks)
}
#Calculate dynamic fecundity for sharks
for (i in 1:length(fy)) {
FY[i] <- fy[i] * exp(b * X[7]) # X[7] is the number of adult prey (sea turtles)
}
#Return fecundity values as a list
return(list(FX = FX, FY = FY))
}
# Function to update the combined Leslie matrix
update_matrix <- function(L_turtles, L_sharks, FX, FY) {
# Create an empty combined matrix
A <- matrix(0, nrow = 10, ncol = 10)
#Insert fecundity values into the turtle matrix
A[4, 5] <- FX[4] # Fecundity for age class 4
A[5, 6] <- FX[5] # Fecundity for age class 5
A[6, 7] <- FX[6] # Fecundity for age class 6
#Insert survival into the turtle matrix
A[2, 1] <- L_turtles[2, 1]
A[3, 2] <- L_turtles[3, 2]
A[4, 3] <- L_turtles[4, 3]
A[5, 4] <- L_turtles[5, 4]
A[6, 5] <- L_turtles[6, 5]
A[7, 6] <- L_turtles[7, 6]
# fecundity values into shark matrix
A[8, 9] <- FY[2] # Fecundity for shark age class 2
A[9, 10] <- FY[3] # Fecundity for shark age class 3
#survival rates into shark matrix
A[9, 8] <- L_sharks[2, 1] # Survival rate SY1
A[10, 9] <- L_sharks[3, 2] # Survival rate SY2
return(A)
}
# population sizes
X <- initial_sea_turtle_pop
Y <- initial_tiger_shark_pop
#dynamic fecundity for each age class
fecundity <- calculate_fecundity(L_turtles, L_sharks, a, b, X, Y)
#Update Leslie matrix with dynamic fecundity values
A <- update_matrix(L_turtles, L_sharks, fecundity$FX, fecundity$FY)
print(A)Editor is loading...
Leave a Comment