[R] About an integral univariate problem

R. Michael Weylandt michael.weylandt at gmail.com
Tue Oct 18 16:25:57 CEST 2011


How about adding an additional argument to fun?

R> fun <- function(x, y) exp(-x)*sum(y^x)
R> y <- c(2,3,5)
R> integrate(fun, 0, 3, y)
[1] 346.853 with absolute error < 3.9e-12
Michael

On Tue, Oct 18, 2011 at 10:01 AM, Freddy Hernandez Barajas
<fhernanb at gmail.com> wrote:
> Hello all R users
>
> I want to calculate this univariate integral:
> exp(-x)*sum(y^x)  respect to x  from 0 to 3  where y is a vector y=(2,3,5).
> In fact, the original y vector has a large number of elements but I propose
> with 3 elements.
>
> I know that I can resolve this problem doing
>
> fun <- function(x) exp(-x)*(2^x+3^x+5^x)
> integrate(fun,0,3)
>
> When the y vector has a large number of elements the last solution is not
> possible,
> if I use this another way I can not obtain the true answer
>
>   y <- c(2,3,5)
> fun1 <- function(x) exp(-x)*sum(y^x)
> integrate(fun1,0,3)
>
> Someone could give me a help with the problem?
> Thanks.
>
>
> Freddy Hernández Barajas
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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