[R] an integration question

Spencer Graves spencer.graves at pdf.com
Mon Sep 13 19:00:19 CEST 2004

```      I'm not certain what you mean by "primitive", but for x <= 7.5, by
my computation, the integral is 5*exp(-1.5)*(1-exp(-0.2*x)).  For x =
7.5, this is  0.8667155, which is exactly what I got from "integrate".
For x > 7.5, the integral is this constant plus exp(-3)*(x-7.5).

hope this helps.  spencer graves

Vito Muggeo wrote:

>Dear all,
>I'm stuck on a problem concerning integration..Results from the analytical
>expression and numerical approximation (as returned by integrate()) do not
>match.
>It probably depends on some error of mine, so apologizes for this off-topic
>question.
>
>I'm interested in computing the integral of f where:
>f<-function(x){exp(-3-.2*pmin(x-7.5,0))}
>x<-seq(0,15,length=50)
>plot(x, f(x),type="l")
>
>Using the integrate() function, I get reasonable results
>a<-sapply(x, function(xx)integrate(f,0,xx)[[1]])
>plot(x, a,type="l")
>
>Using analytical expression, the primitive of f is (or should be..)
>F<-function(x){exp(-3-.2*pmin(x-7.5,0))/(-.2*I(x<7.5))}
>plot(x,(F(x)-F(0)), type="l")
>
>The problem is that for x>7.5 the denominator (-.2*I(x<7.5)) is zero and
>then the primitive function F(.) goes to infinity. On the other hand
>integrate() provides finite (as it should be, I believe) output. For x<7.5
>everything works.
>
>
>
>>F(10)-F(0)
>>
>>
>[1] -Inf
>..
>
>
>>integrate(f,0,10)
>>
>>
>0.9911831 with absolute error < 1.1e-14
>
>
>>F(5)-F(0)
>>
>>
>[1] 0.7052258
>..
>
>
>>integrate(f,0,5)
>>
>>
>0.7052258 with absolute error < 7.8e-15
>
>Hence I think there is an error in the expression of H(.), but I can not
>figure out where it is..Please can anyone help me? I would like to get an
>analytical expression for F.
>
>Many thanks,
>
>vito
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help