I am trying to use the following code to calculate the integrate and double integrate. I used the 'trapz' to perform integration with respect to time and find area under the curve (AUC_C and AUC_fvfree).

Now I want to calculate AUC which should be calculated as AUC = ∬fv$C*fv_free with respect to time for each variable. So. it may be written as : AUC = ∫fv$C dt * ∫fv_free dt . I was thinking of maybe applying a code that calculates partial AUCs at each time point to calculate each integral term in AUC separately and then adding them up. However, I could not find any specific command/code that will calculate partial AUC at each time point. Is there a way to work around this ?? Any inputs will be helpful ..

Thanks

library (deSolve)

library(rootSolve)

library(pracma)

ka = 0.1; CL = 0.2; Ke = 0.3; R = 10; KD = 0.1

LV <- function(time,state, params)

{ C <- state[1]

P <- state[2]

fun_sp <- function(p){p + ((C/R)*p/(p+(KD/R))) -1}

p <<- uniroot.all(fun_sp, c(0,1))

fb <- p/(p+(KD/R))

dC <- fb *ka* C - CL *C + P* CL - Ke*C

dP <- CL *C - P* CL

list(c(dC, dP), free = fb) }

state_ini = c(C=100,P=0)

time = c(seq(1, 24 , 1))

fv <- ode(state_ini, time, LV, parms, method = "lsoda", rtol=1e-6, atol=1e-6, verbose=FALSE)

fv = as.data.frame(fv)

str(fv)

fv_free <- fv$free

AUC_C <- trapz(time, fv$C) ## integration of fv$C w.r.t. time

AUC_fvfree <- trapz(time, fv_free) ## integration of fv_free w.r.t. time

AUC <- ???