Dear list

The deSolve package allows you to specify the model code in C or Fortran.
Thanks to the excellent vignette this works fine. However I have not yet
managed to use forcing functions in C code.

In pure R code this works very well with approxfun() specified outside the
model:

###############################################
#Model
lvml <- function(t, x, parms) {
       with(as.list(c(parms, x)), {
     import <- sigimp(t)
         dS <- import - b*S*P + g*K     #substrate
         dP <- c*S*P  - d*K*P           #producer
         dK <- e*P*K  - f*K             #consumer
         res <- c(dS, dP, dK)
         list(res)
       })
     }

## Parameters
     parms  <- c(b = 0.0, c = 0.1, d = 0.1, e = 0.1, f = 0.1, g = 0.0)
## vector of timesteps
     times  <- seq(0, 100, length = 101)
## external signal with rectangle impulse
     signal <- as.data.frame(list(times = times,
                                 import = rep(0,length(times))))
signal$import[signal$times >= 10 & signal$times <= 21] <- 0.2
sigimp <- approxfun(signal$times, signal$import, rule = 2)
 ## Start values for steady state
y <- xstart <- c(S = 1, P = 1, K = 1)
## Solving
out2 <- as.data.frame(lsoda(xstart, times, lvml, parms))
###############################################

I would like to do the same thing in C, and my guess is that the approx1
function has to be used in some way. So far did not figure out how. If
anyone has managed to do so, or know how to approach this problem, please
let me know.

Best wishes
Glenn

	[[alternative HTML version deleted]]


