title: vectorized operation in r, evaluating an integral depending on two parameters
body: <p>evaluating an integral depending on two parameters</p>
  
  <pre><code>A &lt;- 0.0004
  B &lt;- 0.0013
  c &lt;- 1.0780
  
  f1 &lt;- function(x) {
      f2 &lt;- function(s) {
          A + B * c^(x+s)
      }
  
      return(f2)
  }
  
  tpx &lt;- function(t,x) {
      exp(-integrate(f1(x), lower=0, upper=t)$value)
  }
  </code></pre>
  
  <p>i get</p>
  
  <pre><code>&gt; tpx(1,1)
  [1] 0.9981463
  </code></pre>
  
  <p>for the ordered pair (1,1). when using the colon operator</p>
  
  <pre><code>&gt; tpx(1,1:2)
  [1] 0.9980945
  Warning messages:
  1: In x + s :
    longer object length is not a multiple of shorter object length
  2: In x + s :
    longer object length is not a multiple of shorter object length
  3: In x + s :
  </code></pre>
  
  <p>some error messages occur. is it possible to adjust the integration variable <code>s</code>? what causes the output right before the warning messages? it is neither</p>
  
  <pre><code>&gt; tpx(1,1)
  [1] 0.9981463
  </code></pre>
  
  <p>nor</p>
  
  <pre><code>&gt; tpx(1,2)
  [1] 0.998033
  </code></pre>
  
  <p>i suppose i get something wrong :S</p>