title: Insert loops in ode model
body: <p>I build a model and want to insert some loops for state value, but it doesn't work. I simple the model as below, ia,ib,ic,id are matrix for state values. Does anyone have solution? </p>
  
  <pre><code>Mod&lt;-function(t, parms){
    derivs&lt;-function(t, state, parms){
      with(as.list(c(state, parms)),{
        dA=k1*a-k2*b
          dB=k1*a+aa
          dC=k2*c-bb
          dD=k2*d-k1*c
          return(list(c(dA,dB,dC,dD),
                      IRAB=dA/dB))
      })
  
    }
  
    betavec &lt;- seq(1,14,by=1)
  
    res &lt;- as.vector(data.frame(1:5, 1:14),mode="numeric")
  
  for (k in seq_along(betavec)){
  
  res[[k]]&lt;-ode(y=c(a=ia[1,k],b=ib[1,k]*eAA[1,k],c=ic[1,k]*eAA[1,k],d=id[1,k]),times=time,func=derivs,parms=parms, method ="rk4")
  
    }
  }
  
  pars&lt;-c( k1=1,k2=1)
  
  Objective&lt;-function(x, parset=names(x)){
  
    pars[parset]&lt;-x
  
    tout&lt;-d1$time
  
    out&lt;-Mod(tout,pars)
  
    return(modCost(obs=d1, model=out, y="val", err="err"))
  }
  
  lower = c( k1=0, k2=0)
  upper=c( K1=10,  K2=10)
  
  m1&lt;-modFit(p=pars, f=Objective,lower=lower, upper=upper, method="Marq")
  
  summary(m1)
  </code></pre>