[R] efficiently finding the integrals of a sequence of functions
Zuofeng.Shang.5 at nd.edu
Sat Dec 10 07:36:39 CET 2011
I am having a question about efficiently finding the integrals of a list of
functions. To be specific,
here is a simple example showing my question.
Suppose we have a function f defined by
Thus, f is actually corresponding to three uni-dimensional functions
f_1(x)=x, f_2(y)=y^2 and f_3(z)=z^3.
What I am looking for are the integrals of these three functions f_1,f_2,f_3
over some interval, say, (0,1).
More specifically, the integrals \int_0^1 f_1(x) dx, \int_0^1 f_2(y) dy and
\int_0^1 f_3(z) dz.
For this simple example, of course we can do these three integrals one by
integrate (f_1, lower=0, upper=1)
However, in practice, I have a sequence of 5000 uni-dimensional functions
and hope to find all of their
integrals (over some regions), so using loops to do this one by one is not
A possible idea is to convert the sequence of functions to a list of
objects, and use sapply()
which allow us to find the integrals in a fashion of vectorizing. But I
don't know how to convert
the above example function f to a list. In my research problem, I can only
define the 5000 functions
in a vectorizing way like
So how to convert it to a list will be a crucial step to efficiently get the
Thanks for all the suggestions!
View this message in context: http://r.789695.n4.nabble.com/efficiently-finding-the-integrals-of-a-sequence-of-functions-tp4179452p4179452.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help