mardi 2 mai 2017

step function in an ODE system in R

i am reletively new to r and programming in general but i was trying to make a step function in an ODE system in R by using an if statement and it does not seem to be working for me. I have posted the code below, does anyone have any ideas?

equation <- (function(t, state, parameters) 
  with(as.list(c(state, parameters)),{ 
    # rate of change 

    dS <- (-(a*S*I)/n) - ((r*S*D)/n) 
    dE <- (a*S*I)/n + ((r*S*D)/n) - i*E 
    (if (h >= Q) 
                e = e 
              else if (h < Q )   
                e = 0   
    dI <- i*E - (e)*I - c*I - d*I ) 

    ( if (h >= Q) 
                e = 1 
              else if (h < Q )   
                e = 0,       
    dQ <- j*(e)*I - b*Q - k*Q ) 
    dD <- d*I - r*D 
    dB <- b*Q + r*D 
    dC <- c*I + k*Q 
    dY <- p * (b*Q + r*D) 
    dR <- (1-x)* (p*(b*Q + r*D))  -t*(R) 
    de <- t*(R*s*exp(-R)) 
    dH <- (x)* (p*(b*Q + r*D)) -u*(H) 
    dh <- u*(H/g) 


    # return the rate of change 
    list(c(dS, dE, dI, dQ, dD, dB, dC, dY, dR, de, dH, dh )) 
  }))

Aucun commentaire:

Enregistrer un commentaire