Root finder function Rstudio

I am trying to execute the following code where the main function ()LV includes another function (fun_sp) for finding the root at each time point. The root is called p. As per my understanding, p is dependent upon a variable C which is a vector and changes at each time point, so p should also be a vector that changes at each time point. But when I output p, I get a single value only. am I understanding it wrongly ?
Any inputs will be helpful ?

rm(list = ls())
library(deSolve)
library(rootSolve)

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))
}

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)
p
fv
fv = as.data.frame(fv)
str(fv)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.