Hi everyone, I'm trying to integrate f(x) over x where f(x) does not have a close form but only numerical values at certurn knots of x. Is there a way that I can use any generical R function (such as integrate) or any package to do so? Thanks! I appreciate your time. Best Regards, Martha Cao
You might try the statmod package which provides nodes and weights for gaussian quadrature.> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Xiaofan Cao > Sent: Wednesday, November 08, 2006 12:43 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Numerical Integration > > Hi everyone, > > I'm trying to integrate f(x) over x where f(x) does not have > a close form but only numerical values at certurn knots of x. > Is there a way that I can use any generical R function (such > as integrate) or any package to do so? > > Thanks! I appreciate your time. > > Best Regards, > Martha Cao > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
You could approximate it with splines and then integrate that: x <- 0:10/10 f <- function(x) 1 + x + x^2 + x^3 + x^4 y <- f(x) fs <- splinefun(x, y) integrate(fs, 0, 1) integrate(f, 0, 1) On 11/8/06, Xiaofan Cao <cao at stat.colostate.edu> wrote:> Hi everyone, > > I'm trying to integrate f(x) over x where f(x) does not have a close form > but only numerical values at certurn knots of x. Is there a way that I can > use any generical R function (such as integrate) or any package to do so? > > Thanks! I appreciate your time. > > Best Regards, > Martha Cao > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >