[R] Numerical Integration

Gabor Grothendieck ggrothendieck at gmail.com
Wed Nov 8 19:18:33 CET 2006


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.
>



More information about the R-help mailing list