Oops, that's not right. The trigger condition should be init[1]>=30. The
way I have it now I think init[1]=1. I don't know how to fix that yet
because it won't take and if construct ... more reading for me I guess ...

Thanks for pointing that out.

Jannetta


On 11 February 2013 00:09, David Winsemius <dwinsem...@comcast.net> wrote:

>
> 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@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> Alameda, CA, USA
>
>


-- 

===================================
Web site: http://www.jannetta.com
Email: janne...@henning.org
===================================

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to