[R] Integrate a 1-variable function with 1 parameter (Jose L. Romero)

Ravi Varadhan RVaradhan at jhmi.edu
Wed Aug 27 16:42:24 CEST 2008


Here is one way:

integrand <- function (t, x) {
	exp(-2*t)*(2*t)^x/(10*factorial(x))
}

x <- 0:44
ans <- sapply(x, function(x) integrate(integrand, lower=0, upper=10, x=x))
cbind(x=x, integral=unlist(ans[1,]), abs.error=unlist(ans[2,]))
 

Ravi.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of jose romero
Sent: Wednesday, August 27, 2008 10:24 AM
To: r-help at r-project.org
Subject: [R] Integrate a 1-variable function with 1 parameter (Jose L.
Romero)

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