g <- function(x,h,n) { return (pmin(1,(x/(2*h))^n))}      # Type 1
f <- function(x,h,n) { return (x^n/(h^n + x^n))}          # Hill function
f2 <- function(x,h,g) {                                   # Curvature
  H = h/(1-0.5*g)
  return(2*x/(H + x + sqrt((H+x)^2 - 4*g*H*x)))
}
p <- function(x,h,n) { return (1-(x/h)^n)}
ph <- function(x,h,n) { return (1-(x/(2^(1/n)*h))^n)}
b <- function(x,y,h) { return (x/(h + x + y))}

curve(1-x,from=0,to=1,ylim=c(0,1),lwd=1,col="black",ylab="f(x)")
curve(1-x^2,from=0,to=1,ylim=c(0,1),lwd=2,col="red",add=T)
curve(1-x^0.5,from=0,to=1,ylim=c(0,1),lwd=1,col="blue",add=T)

curve(g(x,0.25,1),from=0,to=2,ylim=c(0,1),lwd=1,col="black",ylab="f(x)")
curve(f(x,0.25,1),from=0,to=2,ylim=c(0,1),lwd=2,col="red",add=T)
curve(f(x,0.25,5),from=0,to=2,lwd=2,col="blue",add=T)
curve(f2(x,0.25,0.99),from=0,to=2,ylim=c(0,1),lwd=2,col="darkgreen",add=T)

curve(1-g(x,0.25,1),from=0,to=2,ylim=c(0,1),lwd=1,col="black",ylab="f(x)")
curve(1-f(x,0.25,1),from=0,to=2,ylim=c(0,1),lwd=2,col="red",add=T)
curve(1-f(x,0.25,5),from=0,to=2,lwd=2,col="blue",add=T)
curve(1-f2(x,0.25,0.99),from=0,to=2,ylim=c(0,1),lwd=2,col="darkgreen",add=T)

curve(f(x,0.1,2)*(1-f(x,1,2)),from=0,to=2,ylim=c(0,1),lwd=2,col="red",ylab="f(x)(1-f(x)")
      
curve(p(x,1,1),from=0,to=2,ylim=c(0,1),lwd=1,col="black",ylab="f(x)")
curve(p(x,1,2),from=0,to=2,ylim=c(0,1),lwd=2,col="red",add=T)
curve(p(x,1,0.5),from=0,to=2,lwd=2,col="blue",add=T)
curve(ph(x,1,1),from=0,to=2,ylim=c(0,1),lwd=1,col="black",ylab="f(x)")
curve(ph(x,1,2),from=0,to=2,ylim=c(0,1),lwd=2,col="red",add=T)
curve(ph(x,1,0.5),from=0,to=2,lwd=2,col="blue",add=T)

curve(b(x,0,1),from=0,to=10,ylim=c(0,1),lwd=1,col="black",ylab="f(x)")
curve(b(x,1,1),from=0,to=10,ylim=c(0,1),lwd=2,col="red",add=T)
curve(b(x,10,1),from=0,to=10,ylim=c(0,1),lwd=2,col="red",add=T)

# Make Figures
size<-5#inch

pdf("hollingA.pdf",width=size,height=size)
par(mar=c(0.1,0.1,0.1,0.1),xaxt="n",yaxt="n",ann=F,xaxs="i",yaxs="i")
curve(g(x,0.25,1),from=0,to=2,ylim=c(0,1.2),lwd=2,col="red")
dev.off()

pdf("hollingB.pdf",width=size,height=size)
par(mar=c(0.1,0.1,0.1,0.1),xaxt="n",yaxt="n",ann=F,xaxs="i",yaxs="i")
curve(f(x,0.25,1),from=0,to=2,ylim=c(0,1.2),lwd=2,col="red")
dev.off()

pdf("hollingC.pdf",width=size,height=size)
par(mar=c(0.1,0.1,0.1,0.1),xaxt="n",yaxt="n",ann=F,xaxs="i",yaxs="i")
curve(f(x,0.25,2),from=0,to=2,ylim=c(0,1.2),lwd=2,col="red")
dev.off()
