[R] lower and upper limits in integrate as vectors
Andreas Wittmann
andreas_wittmann at gmx.de
Sat Sep 20 14:08:22 CEST 2008
Dear R useRs,
i try to integrate the following function for many values
"integrand" <- function(z)
{
return(z * z)
}
i do this with a for-loop
for(i in 2:4)
{
z <- integrate(integrand, i-1, i)$value
cat("z", z, "\n")
}
to speed up the computation for many values i tried vectors
in integrate to do this.
vec1<-1:3
vec2<-2:4
integrate(Vectorize(integrand), vec1, vec2)$value
but here it seems the integration works only for the first values of
vec1 and vec2.
If you have any advice how i can to this computations with vectors or
something like that, i would be very thankful,
best regards
Andreas
More information about the R-help
mailing list