2

I am wondering if it is possible to calculate the integration of a integral function.

140t sin(x)dx dt

I try to define a R function for the integral function by build in function integrate, however, it seems that this function cannot handle vector calculation.

f <- function(x){sin(x)}
int_f <- function(f,lower=0,upper){return(integrate(f,lower,upper)$value)}

I try to treat int_f as an input in integrate, then it does not work.

Using areas of rectangle to approximate the integral is my current solution, however, the problem is that the for loop cannot be avoided, it is very time consuming.

Do you have any idea? Or is there any function which can calculate the integral with a bunch of upper limit?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
ANuo
  • 79
  • 7
  • @m0nhawk thank you for editing my post. – ANuo Apr 19 '16 at 07:57
  • NP, just a bunch of formatting improvements. Also, [this](http://stackoverflow.com/questions/8913603/calculating-double-integrals-in-r-quickly) may be useful. I don't think this is possible with `integrate` function directly, it uses numerical methods and it can't held the limits with a variables. – m0nhawk Apr 19 '16 at 07:58
  • Yes, I have the same feeling. Let's wait for other suggestions – ANuo Apr 19 '16 at 08:10

0 Answers0