提问人:Crimson 提问时间:11/17/2023 更新时间:11/17/2023 访问量:22
如何测量等斜线的值或测量给定某个 x 值的 y 值?
How to measure the value of isoclines or measure a y value given some x value?
问:
此代码生成两个图形,用于查看基于 Lotka-Volterra 模型的捕食者-猎物关系。一张图显示了代表捕食者和猎物种群的两个函数。这些随时间推移,t(横轴)相对于垂直轴上的N(人口增长)起伏。另一张图是周期性的,显示了守恒能量的性质。
也就是说,如何在起伏图上测量时间 t 处的 N 值,以及如何测量第二个周期图的等斜线值?也就是说,如何计算捕食者等斜线的 x 值和猎物等斜线的 y 值?
# Activity 1
library('deSolve') # load the library to be able to integrate
#### THIS SECTION SETS UP THE MODEL. DON'T TOUCH ####
vp_func1 = function(t, N, params){ # this is the function. Don't touch this.
V = N[1] # the population size of Victims
P = N[2] # the population size of Predators
r = params[1] # per capita growth rate of Victims
a = params[2] # capture efficiency of Predators
c = params[3] # conversion efficiency of Predators
q = params[4] # mortality of Predators
dV = r*V - a*V*P # Victim population growth rate
dP = c*a*V*P - q*P # Predator population growth rate
return(list(c(dV, dP)))
}
#### SET UP INITIAL CONDITIONS AND PARAMETERS ####
V = 4 # Initial Victim population size
P = 6 # Initial Predator population size
N0 = c(V,P) # Put the initial population sizes into a vector
r = 3.1 # Victim per capita growth rate
a = 0.25 # Capture efficiency
c = 0.5 # Conversion efficiency
q = 0.4 # Predator mortality rate
params = c(r, a, c, q) # Put parameters into a vector.
t = seq(0, 50) # run for 50 time steps
#### RUN THE MODEL. DON'T TOUCH! ####
results = round(data.frame(ode(N0, t, vp_func1, params)), 2)
#### TIME SERIES GRAPH. DON'T TOUCH! ####
#### (unless you want to change colors, etc) ####
plot(results$time, results$X1, type='l',
ylab='N',
xlab='t',
col='blue',
ylim=c(0, max(1.1*results$X1, 1.1*results$X2)))
lines(results$time, results$X2,
col='red')
legend('topleft',
lty=c(1,1),
legend=c('Victims', 'Predators'),
col=c('blue', 'red'))
#### STATE-SPACE GRAPH. DON'T TOUCH! ####
#### (unless you want to change colors, etc) ####
plot(results$X1, results$X2, type='l',
ylab='Predators',
xlab='Victims',
ylim=c(0, 1.1*max(results$X2)),
xlim=c(0, 1.1*max(results$X1)))
points(N0[1], N0[2], pch=16, cex=1.5)
abline(r/a, 0,
col='blue')
abline(v = q/(c*a),
col='red')
legend('topright',
lty=c(1,1,1),
legend=c('Victim Isocline', 'Predator Isocline', 'Population Trajectory'),
col=c('blue', 'red', 'black'))
答: 暂无答案
评论