title: How to deal with optim when some parameters become known?
body: <p>I have faced a problem with passing arguments to <code>optim</code>.
  Suppose I want to do box constraint minimization on a multivariate function, for example</p>
  
  <pre><code>fr &lt;- function(x) {   ## Rosenbrock  function
    x1 &lt;- x[1]
    x2 &lt;- x[2]
    x3 &lt;- x[3]
    x4 &lt;- x[4]
    100 * (x2 - x1 * x1)^2 + (1 - x1)^2 +
    100 * (x3 - x2 * x2)^2 + (1 - x2)^2 +
    100 * (x4 - x3 * x3)^2 + (1 - x3)^2
  }
  </code></pre>
  
  <p>As usual <code>optim</code> can be used as following:</p>
  
  <pre><code>optim(par = c(0, 1, 1, 2), fr, method = "L-BFGS-B", lower = c(0, 0, 0, 0), upper = c(3, 3, 3, 3))
  </code></pre>
  
  <p>Now, suppose this procedure repeated in an algorithm which changes <code>lower</code> and <code>upper</code> (box constraints), followed by <code>par</code>, such that in some iterations one, two or three value of  parameters become known, for example <code>x1</code> = 1. in this case I expect <code>optim</code> to handle this by setting the initial value, lower and upper bounds of <code>x1</code> to 1:</p>
  
  <pre><code>optim(par = c(1, 1, 1, 2), fr, method = "L-BFGS-B", lower = c(1, 0, 0, 0), upper =    c(1, 3, 3, 3))
  </code></pre>
  
  <p>But by runnig this line I got an error:</p>
  
  <pre><code>Error in optim(par = c(1, 1, 1, 2), fr, method = "L-BFGS-B", lower = c(1,  : non-finite finite-difference value [1]
  </code></pre>
  
  <p>Now, the question is how can I deal with this feature of <code>optim</code> without defining many new functions when one or some of the parameters become known?</p>
  
  <p>Thank you in advance</p>