title: Dynamic optimization (fishery model)
body: <p>I'm trying to set up a model where fishermen choose the level of fishing effort that maximizes their sum of profits over time.  I'm using a simple logistic growth equation and everything seems to work fine, except I just can't figure out how to run <code>optim</code> to get a solution.  Can <code>optim</code> find the vector of <code>e[i]</code> that maximizes profits?  Here's the code I'm using:</p>
  
  <pre><code># Optimal fishery management by choosing effort
  
  # Set parameters
  
  r = 0.1       # intrinsic growth rate
  K = 1         # carrying capacity
  q = 0.01      # catchability
  eta = 0.3     # stiffness parameter
  p = 200       # price of fish
  c = 1         # unit cost of effort
  
  eo = 1        # initial effort
  xo = 1        # initial biomass
  Yo = 0.01     # initial growth (meaningless)
  Ho = 0.01     # initial harvest (meaningless)
  
  # set time periods
  
  time &lt;- seq(0,50)
  
  # Logitstic growth
  
  x &lt;- rep(xo,length(time))                  # vector for stock biomass
  Y &lt;- rep(Yo,length(time))                  # vector for growth in the stock
  H &lt;- rep(Ho, length(time))                 # vector for harvest
  e &lt;- rep(eo, length(time))                  # vector for effort
  profit &lt;- rep(0, length(time))              # vector for profit
  
  for (i in 2:length(time)){
      x[i]=x[i-1]+Y[i-1]-H[i-1]             # stock equation
      H[i]=q*x[i]*e[i]                  # harvest equation
      Y[i]=r*x[i]*(1-x[i]/K)                # growth equation
      profit[i] = p*H[i]-c*e[i]             # profit equation
      }
  
  totalprofit &lt;- function(e, x){-sum(p*q*x[i]*e[i]-c*(e[i]))}
  
  optim(par = eo, totalprofit, x=x[i], method = "Brent", lower = 0, upper = 20 )
  </code></pre>