title: How can I optimize the expected value of a function in R?
body: <p>I have derived a survival function for a system of components (ignore the details of how this system is setup) and I am trying to maximize its expected, or more specifically, maximizing the expected value of the function:</p>
  <pre><code>surv_func = function(x,mu) = {(exp(-(x/(mu))^(1/3))*((1-exp(-(4/3)*x^(3/2)))+exp(-(-(4/3)*x^(3/2)))))*exp(-(x/(3-mu))^(1/3))}
  </code></pre>
  <p>and I am supposed (since the pdf including my tasks gives a hint about it) to use the function</p>
  <pre><code>optimize()
  </code></pre>
  <p>and the expected value for a function can be computed with</p>
  <pre><code># Computes expected value of a the function &quot;function&quot;
  E &lt;- integrate(function, 0, Inf)
  </code></pre>
  <p>but my function depends on <strong>x</strong> and <strong>mu</strong>. The expected value could (obviously) be computed if the integral had no <strong>mu</strong> but instead only depended on <strong>x</strong>. For those interested, the <strong>mu</strong> comes from the fact that one of the components has a <em>Weibull</em>-distribution with parameters <em>(1/3,mu)</em> and the 3-mu comes from that has a <em>Weibull</em>-distribution with parameters <em>(1/3,lambda)</em>. In the task there is a constraint <em>mu + lambda = 3</em>, so I tought substituting the <em>lambda</em>-parameter in the second <em>Weibull</em>-distribution with <em>lambda = 3 - mu</em> and trying to maximize this problem would yield not only mu, but also lambda.</p>
  <p>If I try to, just for the sake of learing about R, compute the expected value using the code below (in the console window), it just gives me the following:</p>
  <pre><code>&gt; E &lt;- integrate(surv_func,0,Inf)
  Error in (function (x, mu)  : argument &quot;mu&quot; is missing, with no default
  </code></pre>
  <p>I am new to R and seem to be a little bit &quot;slow&quot; at learning. How can I approach this problem?</p>