例1:y'=ry(1-y/K) y(0)=2 對應的R代碼為: library(deSolve)#parameters and initial valuesr<-1K<-10yini<-2#the function derivs<-function(t,y,parms){ return(list(r ...
例1:y'=ry(1-y/K)
y(0)=2
對應的R代碼為:
library(deSolve)
#parameters and initial values
r<-1
K<-10
yini<-2
#the function
derivs<-function(t,y,parms){
return(list(r*y*(1-y/K)))
}
#the independent variables
times<-seq(from=0,to=20,by=0.2)
#to calculate y values
out<-ode(y=yini,times=times,func=derivs,parms=NULL)
#the results
out
參考文獻:
Karline S, Thomas P, Setzer R W. Solving Differential Equations in R[M]. Springer Publishing Company, Incorporated, 2012.