#Deterministic model based on #Boots, M. and Y. Haraguchi. 1999. The evolution of costly resistance in #host-parasite systems. Am. Nat. 153: 359-370 rm(list=ls()) require(odesolve) #Models ****************************************************************** #second ODE linearcost=function(t,y,parms){ #Assign values of y to state variables. #This order must be maintained in the inital conditions. X1 = y[1] #Equations for system of ODEs r=a*X1+b xeq=g/X1 yeq=(r-q*g/X1)/(X1+q); x1dot=sigma*(a-yeq); #The function must return a list containing the derivatives. xdot = c(x1dot) return(list(xdot)) } #parameter values **************************************************** a= 2 b= 0.012 q= 0.003 g= 1 sigma = 0.01 parms = numeric(5) #initial conditions ********************************************* x10 = 0.4 times=seq(0,3000,by=1) # time steps x0=c(x10) output1 = lsoda(x0,times,linearcost,parms) #plotting ******************************************************************* tm=output1[,1] #time trait=output1[,2] #susceptibility par(mfrow=c(1,1)) plot(tm,trait,xlab="Time",ylab="Susceptibility",lwd=2,col="red",type="l") title(main="Linear Cost no Ecology")