[R] Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Wed Aug 27 16:39:53 CEST 2008
jose romero wrote:
> Hey fellas:
>
> I would like to integrate the following function:
>
> integrand <- function (x,t) {
> exp(-2*t)*(2*t)^x/(10*factorial(x))
> }
>
> with respect to the t variable, from 0 to 10.
> The variable x here works as a parameter: I would like to integrate the said function for each value of x in 0,1,..,44.
>
> I have tried Vectorize to no avail.
>
>
Will this do?
sapply(0:44,function(x)integrate(integrand,x=x, lower=0, upper=10)$value
--
O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list