[R] efficiently finding the integrals of a sequence of functions
JeffND
Zuofeng.Shang.5 at nd.edu
Sun Dec 11 18:11:25 CET 2011
Thanks,Hans!
I agree that this is a good way of solving this problem.
Here is another way. Instead of defining a vector of uni-dimensional
functions and trying to integrating
each component (a uni-dimensional function), we can do something below
my.integrand<-function(x,k)
{
return(f[x,k]) ## use matrix to represent the sequence of uni-dimensional
functions
}
my.integral<-function(k) ## k=1,...,5000 denotes the function labels
{
return(integrate(my.integrand,lower=...,upper=...,k)$value)
}
When calculating the integrals, just perform
sapply(1:5000, my.integral)
This is a way of avoiding loops but the computing time needs to be carefully
examined.
Jeff
--
View this message in context: http://r.789695.n4.nabble.com/efficiently-finding-the-integrals-of-a-sequence-of-functions-tp4179452p4183323.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list