[R] Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Moshe Olshansky
m_olshansky at yahoo.com
Thu Aug 28 03:57:39 CEST 2008
This can be done analytically: after changing a variable (2*t -> t) and some scaling we need to compute
f(x) = integral from 0 to 20 of (t^x*exp(-t))dt/factorial(x)
f(0) = int from 0 to 20 of exp(-t)dt = 1 - exp(-20)
and integration by parts yields (for x=1,2,3,...)
f(x) = -exp(-20)*20^x/factorial(x) + f(x-1) so that
f(x) = 1 - exp(-20)*sum(20^k/factorial(k)) where the sum is for k=0,1,...,x
If I did not a mistake, your original quantity should be f(x)/20.
--- On Thu, 28/8/08, jose romero <jlaurentum at yahoo.com> wrote:
> From: jose romero <jlaurentum at yahoo.com>
> Subject: [R] Integrate a 1-variable function with 1 parameter (Jose L. Romero)
> To: r-help at r-project.org
> Received: Thursday, 28 August, 2008, 12:23 AM
> 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.
>
> Thanks in advance,
> jose romero
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
More information about the R-help
mailing list