使用R在ODE求解器中存储数据两次

时间:2017-06-15 05:49:22

标签: r file ode

请检查以下代码,我想知道它为什么在文件“LV.txt”中存储两次数据值。这是代码后面跟着“LV.txt”文件的代码。另外,为什么时间不像0,0.1,0.2 ...... ......

library(deSolve)

unlink("LV.txt")
predpreyLV<-function(t,y,p){
   N<-y[1]
   P<-y[2]

   write(paste0(t,"  ",N,"  ",P),"LV.txt",append=TRUE)

   with(as.list(p),{
      dNdt<- r*N*(1-(N/1000))-a*P*N
      dPdt<- -b*P+f*P*N
      return(list(c(dNdt,dPdt)))
  })
}

r<-0.5; a<-0.01; f<-0.01; b<-0.2;

p<-c(r=r,a=a, b=b, f=f)
y0<-c(N=25, P=5)
times<-seq(0,1000,0.1)
LV.out<-ode(y=y0,times,predpreyLV, p)

在文件中:

0  25  5
0  25  5
9.99116343466594e-05  25.0010927835007  5.00002497790859
9.99116343466594e-05  25.0010928292789  5.00002498349248
0.000199823268693319  25.0021856585615  5.00004996698548
0.000199823268693319  25.0021857043414  5.00004997256968
0.0412995612856433  25.4556252934873  5.01080199665104
0.0412995612856433  25.4556535740967  5.010807466621

0 个答案:

没有答案