两个物种的离散时间竞争-通过矢量实现,但因矩阵而停滞

时间:2019-04-17 10:07:37

标签: r rstudio

我已经使用vector在Rstudio上绘制了两个不同的物种种群(虚构的,用于训练):

##I-With vectors : 

#Parameters
alphs <- matrix(c(0.01, 0.005, 0.008, 0.01), ncol = 2, byrow = TRUE)
years<-20
R1<- 0.9
R2<- 1.4

#Creating vectors
TimeVec<-seq(0,years,1)
N1<-rep(0,years)
N2<-rep(0,years)

#INITIALIZATION
N0 <- 50
N1[1] <-N0
N2[1] <-N0

for (t in 1:years){
  N1[t+1]<-(R1*N1[t])/(1+alphs[1,1]*N1[t]+alphs[1,2]*N2[t])
  N2[t+1]<-(R2*N2[t])/(1+alphs[2,1]*N1[t]+alphs[2,2]*N2[t])
}
plot(TimeVec,N1,type="l",xlab='Time (years)',ylab='Population Density',col='blue')
lines(TimeVec,N2,type="l",lwd=2,col='green')
legend("topright", legend = c("Species 1", "Species 2"),lty = 1, col = c("blue", "green"), bty = "n")

我正在尝试使用矩阵以其他方法测试结果。但是由于我是新手,所以不确定自己是否在正确使用它们,也无法获得与上述代码相同的图形。

我尝试使用上周做过的类似练习,使用两个不同的生命周期,而不是两个可以很好地与矩阵配合使用的物种(Litteraly Nj和Na代替N1和N2),如下所示:

##Density dependance with matrix : 

#Parameters
zeta<-0.05
fert<-6
fert0<-30
matur<-0.9
sj<-0.2
sa<-0.6
years<-20
lambda<- 1.389 
##Creating input matrix
X<-matrix(0,2,years+1)

##Creating vectors
TimeVec<-seq(0,years,1)

##INITIALIZATION
N0 <- 30
X[1,1]<- 0 # initial number of juveniles
X[2,1]<- 30 # initial number of adults

for (t in 1:years){
  A<-matrix(c((1-matur)*sj,(fert0/(1+zeta*X[2,t])),matur*sj,sa),nrow=2,ncol=2,byrow=TRUE) 
  X[,t+1]<-A%*%X[,t]
}
plot(TimeVec,X[1,],type="l",xlab='Time (years)',ylab='Population Density',col='blue')
lines(TimeVec,X[2,],type="l",lwd=2,col='orange')
legend("topright", legend = c("Juveniles", "Adults"),lty = 1, col = c("blue", "orange"), bty = "n")

(这里,X是一个矩阵,其中第一行包含Nj,第二行包含Na。)

但是,方程与本示例非常不同,我无法在物种竞争中采用完全相同的方式,并且我的A矩阵最终得到的数据向量仅包含两个不同的条目,而不是四个:

##II-With matrix : 

#Parameters
alphs <- matrix(c(0.01, 0.005, 0.008, 0.01), ncol = 2, byrow = TRUE)
years<-20
R1<- 0.9
R2<- 1.4

##Creating input matrix
X<-matrix(0,2,years+1)

##Creating vectors
TimeVec<-seq(0,years,1)

##INITIALIZATION
N0 <- 50
X[1,1]<- N0 # initial number of individuals from species 1
X[2,1]<- N0 # initial number of individuals from species 2

for (t in 1:years){
  A<-matrix(c(R1/(1+alphs[1,1]+alphs[1,2]),R2/(1+alphs[2,1]+alphs[2,2])),nrow=2,ncol=2,byrow=TRUE)
  A
  X
  ##A<-matrix(c(R1*alphs[1,1], alphs[1,2], alphs[2,1], R2*alphs[2,2]),nrow=2,ncol=2,byrow=TRUE)
  X[,t+1]<-A%*%X[,t]
}
plot(TimeVec,X[1,],type="l",xlab='Time (years)',ylab='Population Density',col='blue')
lines(TimeVec,X[2,],type="l",lwd=2,col='green')
legend("topright", legend = c("Species 1", "Species 2"),lty = 1, col = c("blue", "green"), bty = "n")

在给定相同的初始条件(在“参数”和“初始化”中列出)的情况​​下,我想要的是与第一个代码块相同的图形。因为现在不是这样,我也不明白为什么。也许实际上是数学问题?

0 个答案:

没有答案