[R] A Hodgkin Huxley Model

David Winsemius dwinsemius at comcast.net
Mon Feb 11 01:09:35 CET 2013


On Feb 10, 2013, at 3:35 PM, Jannetta Steyn wrote:

> I managed to get it to work (I think). Code below:
>

The output certainly looks more sensible. You commented out the if- 
reset strategy and are using events. Can you explain how the event  
code is triggered? I no longer see a definition of a v>=30 trigger.  
The vignette says "Events occur when the values of state variables are  
instantaneously changed. They can be specified as a data.frame, or in  
a function. Events can also be triggered by a root function." Is the  
code detecting the sudden rise to infinite values and using that as  
the trigger for a reset?

-- 
David.

> library(deSolve);
> Izhikevich <- function(time, init, parms) {
>  with(as.list(c(init, parms)),{
>    dv <- (0.04*v^2)+(5*v)+140-u+I;
>    du <- a*(b*v-u);
>    #if (v>=30) v<-c else v<-u+d;
>    list( c(dv, du))
>  })}
> parms=c( a=0.02, b=0.2, c=-65, d=2, I=4);
> times=seq(from=1, to=500, by=0.1);
> init=c(v=-65, u=0.2);
>
> root <- function(time, init, parms) init[1]
>
> event <- function(time, init, parms) {
>  with(as.list(c(init, parms)), {
>  init[2] <- init[1] + d
>  init[1] <- c
>  return(init)
>  })
> }
>
> out<-ode(y=init, times=times, func=Izhikevich, parms=parms,
> events=list(func=event, root=TRUE), rootfun=root)
> plot(out)
>
>
> Thanks everybody for their help.
>
> Jannetta
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list