I have parameter values that are specific to each time. I want to feed this parameter values to solve the following ODE: dN/dt = mu*N
where mu = b*(X-12.2)^2
. The X
value changes with time. Please see the code below that I came up with:
library(deSolve)
times = seq(from = 0, to = 2, by = 0.1)
X = c(57.20000, 57.19989, 57.18739, 57.08867, 56.80817, 56.31114, 55.61912,
54.77622, 53.82779, 52.81217, 51.75900, 50.69015, 49.62139, 48.56372,
47.52467, 46.50934, 45.52096, 44.56154, 43.63211, 42.73310, 41.86450)
N0 <- 1
b <- 7.45 # Model parameter
Xmin = 12.2
model <- function(t, y, parms) {
with(as.list(c(y, parms)),{
mu <- b*(X-Xmin)^2
dN <- mu*N
return(list(dN))
})
}
yini <- c(N=N0)
parms <- mu
t <- times
out <- ode(y=yini, times=times, func=model, parms=parms)
X
values are specific to each time i.e. at t = 0, X = 57.2
, t = 0.1, X = 57.19989
and so on....and these need to be supplied to calculate N over time. It is not working. Could anyone help with it?
Thanks,