I am wondering if it is possible to calculate the integration of a integral function.
∫14 ∫0t 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?