title: How to use optim() for sqrt optimization
body: <p>I don't get how to use the optim() function. I tried something simple (at least i thought so). Here is the code:</p>
  
  <pre><code>w&lt;-c(0.5,0.5)
  A&lt;-runif(100)
  B&lt;-runif(100)
  c&lt;-function(w,A,B) sqrt(w[1]*A + w[2]*B)
  optim(w,c)
  Error in w[1]*A:'A' is missing
  </code></pre>
  
  <p>I have seen various questions of this type but I still don't know what is wrong. What am I missing here?</p>