Using R I'd like to automatically find the tangent to a curve of diminishing returns for an optimal foraging graphical exercise. The curve looks like this:
ins <- 40
t <- 30
avg <- 30
curve(ins/2^(x/10+1-1),
0,2*t,xlim=c(-2*t,2*t),ylim=c(ins,0),
xlab="time",ylab="food",type="l",lty=1,col=4,lwd=3,axes=FALSE)
axis(1,pos=ins); axis(2,pos=0)
The tangent starts at points (-40,40) and ideally I would find the point on the curve the tangent would touch.
By trial & error it should look like:
segments(-ins,ins,38,0,col=4,lwd=3,lty=2)