title: uniroot in R when there are two unknowns
body: <p>Consider a function <code>f</code> of two arguments <code>x</code> and <code>a</code>. First I take integration of <code>f</code> with respect to <code>x</code>, which becomes a function <code>g</code> of <code>a</code>. Second, I want to find the root of the resulting function <code>g</code> of <code>a</code>. Can I do this using <code>uniroot</code> and <code>integrate</code> in <code>R</code>? If so, how? If not, is there a way to do this at all? Thanks.</p>
  
  <pre><code>b &lt;- 2
  
  truncfn &lt;- function(x) pmin(b, pmax(x, -b))
  
  # thetashape and thetascale are constants
  # x and a are arguments
  f &lt;- function(x, thetashape, thetascale, a){
    term1 &lt;- -1/thetascale
    term2 &lt;- (1-thetashape)/thetascale
    term3 &lt;- x/(thetascale-thetashape*x)
    term1 + term2*term3 - a
  }
  
  # First, integrate f with respect to x
  g &lt;- integrate(truncfn(f), lower=0, upper=Inf)
  
  # Second, find root of g
  uniroot(g, ...)
  </code></pre>