[R] vectorizing the integrate function
ravi
rv15| @end|ng |rom y@hoo@@e
Sat Aug 10 19:20:13 CEST 2019
Hi all,I am having some difficulties in vectorizing the integrate function. Let me explain with an example.
a <- 10; b <- 3; c <- 4
f <- function(x) {exp(-a*x^3-b*x^2-c*x)}
integrate(f,0,Inf) # works fine
My difficulties start when I want to vectorize.
# attempts to vectorize fail
a <- seq(from=0,to=1,by=0.5)
b <- seq(from=5,to=10,by=1)
m <- seq(from=10,to=20,by=5)
f2 <- function(x,a,b,c) {exp(-a*x^3-b*x^2-m*x)}
fv <- Vectorize(integrate(f2,0,Inf),vectorize.args=c("a","b","m"),SIMPLIFY=TRUE)
I want the result as a 3-d array with dimensions of the lengths of a, b and c. I have tried several variants but am not having much luck. Will appreciate any help that I can get.
Thanks,Ravi Sutradhara
[[alternative HTML version deleted]]
More information about the R-help
mailing list