Thread Subject:
ode45 events - terminate & reset every 10ms

Subject: ode45 events - terminate & reset every 10ms

From: David Cox

Date: 23 Feb, 2012 19:05:16

Message: 1 of 4

Hi,

I have a set of ODEs modelling neuronal spiking in the brain for a period of 200ms. I'm solving this using ode45 and I now want to alter it so that the initial conditions reset every 10ms.

I realise I need to do this using the events option (I've been looking at the BALLODE m file as an example).

However I'm not sure what I need to set 'value' as in my 'events' function because my threshold is for time rather than the output y ?

Below is my code....Many thanks for any help anyone can give me !!!

t = 0:200;
y0 = [60;0];
refine = 4;
options = odeset('Events',@events,'OutputFcn',@odeplot,'OutputSel',1,...
                 'Refine',refine);
tout = 0;
yout = y0.';
teout = [];
yeout = [];
ieout = [];
for i = 1:10
  % Solve until the first terminal event.
  [t,y,te,ye,ie] = ode45(@neuron,t,y0,options);
  if ~ishold
    hold on
  end
  % Accumulate output. .
  nt = length(t);
  tout = [tout; t(2:nt)];
  yout = [yout; y(2:nt,:)];
  teout = [teout; te];
  yeout = [yeout; ye];
  ieout = [ieout; ie];

  ud = get(gcf,'UserData');
  if ud.stop
    break;
  end
  
  % Set the new initial conditions
  y0(1) = 60;
  y0(2) = 0;
  tstart = t(nt);
end
-------------------------------------------------------------------
function [value,isterminal,direction] = events(t,y)
% Stop integration every 10s.
    value = ??????;
    isterminal = 1; % stop the integration
    direction = 0;

end

Subject: ode45 events - terminate & reset every 10ms

From: David

Date: 24 Feb, 2012 06:41:27

Message: 2 of 4

Any advice anyone can give me on this would be greatly appreciated....

I can't find any examples on the web of where someone uses the ode45 'Events' option and sets a time threshold to reset their simulation

"David" wrote in message <ji62lc$69b$1@newscl01ah.mathworks.com>...
> Hi,
>
> I have a set of ODEs modelling neuronal spiking in the brain for a period of 200ms. I'm solving this using ode45 and I now want to alter it so that the initial conditions reset every 10ms.
>
> I realise I need to do this using the events option (I've been looking at the BALLODE m file as an example).
>
> However I'm not sure what I need to set 'value' as in my 'events' function because my threshold is for time rather than the output y ?
>
> Below is my code....Many thanks for any help anyone can give me !!!
>
> t = 0:200;
> y0 = [60;0];
> refine = 4;
> options = odeset('Events',@events,'OutputFcn',@odeplot,'OutputSel',1,...
> 'Refine',refine);
> tout = 0;
> yout = y0.';
> teout = [];
> yeout = [];
> ieout = [];
> for i = 1:10
> % Solve until the first terminal event.
> [t,y,te,ye,ie] = ode45(@neuron,t,y0,options);
> if ~ishold
> hold on
> end
> % Accumulate output. .
> nt = length(t);
> tout = [tout; t(2:nt)];
> yout = [yout; y(2:nt,:)];
> teout = [teout; te];
> yeout = [yeout; ye];
> ieout = [ieout; ie];
>
> ud = get(gcf,'UserData');
> if ud.stop
> break;
> end
>
> % Set the new initial conditions
> y0(1) = 60;
> y0(2) = 0;
> tstart = t(nt);
> end
> -------------------------------------------------------------------
> function [value,isterminal,direction] = events(t,y)
> % Stop integration every 10s.
> value = ??????;
> isterminal = 1; % stop the integration
> direction = 0;
>
> end

Subject: ode45 events - terminate & reset every 10ms

From: Torsten

Date: 24 Feb, 2012 07:33:21

Message: 3 of 4

On 23 Feb., 20:05, "David Cox" <dcwrite...@googlemail.com> wrote:
> Hi,
>
> I have a set of ODEs modelling neuronal spiking in the brain for a period of 200ms. I'm solving this using ode45 and I now want to alter it so that the initial conditions reset every 10ms.
>
> I realise I need to do this using the events option (I've been looking at the BALLODE m file as an example).
>
> However I'm not sure what I need to set 'value' as in my 'events' function because my threshold is for time rather than the output y ?
>
> Below is my code....Many thanks for any help anyone can give me !!!
>
> t = 0:200;
> y0 = [60;0];
> refine = 4;
> options = odeset('Events',@events,'OutputFcn',@odeplot,'OutputSel',1,...
>                  'Refine',refine);
> tout = 0;
> yout = y0.';
> teout = [];
> yeout = [];
> ieout = [];
> for i = 1:10
>   % Solve until the first terminal event.
>   [t,y,te,ye,ie] = ode45(@neuron,t,y0,options);
>   if ~ishold
>     hold on
>   end
>   % Accumulate output.  .
>   nt = length(t);
>   tout = [tout; t(2:nt)];
>   yout = [yout; y(2:nt,:)];
>   teout = [teout; te];
>   yeout = [yeout; ye];
>   ieout = [ieout; ie];
>
>   ud = get(gcf,'UserData');
>   if ud.stop
>     break;
>   end
>
>   % Set the new initial conditions
>   y0(1) = 60;
>   y0(2) = 0;
>   tstart = t(nt);
> end
> -------------------------------------------------------------------
> function [value,isterminal,direction] = events(t,y)
> % Stop integration every 10s.
>     value = ??????;
>     isterminal = 1;   % stop the integration
>     direction = 0;
>
> end

I don't understand. Do your ODEs explicity depend on time ?
Otherwise, by resetting the initial conditions to the starting
conditions,
you'll get the same result over and over again.

Anyhow: As far as I can see, there is no need to use the events
option.
Just call ODE45 in a loop in which you set the start time to the old
end time
and the new end time to the old end time + 10 ms:

tfinal = 200;
deltat = 10;
nend = 20;

For i = 1:nend
[t,y] = ode45(@neuron,[(i-1)*deltat i*deltat],y0,options);
...
[Store solution at time i*deltat and reset initial conditions]
...
end

Best wishes
Torsten.

Subject: ode45 events - terminate & reset every 10ms

From: David

Date: 24 Feb, 2012 22:06:33

Message: 4 of 4

Hi Torsten,

Thanks for your reply. Unfortunately I think I do need the events function. I'll try and explain.

Basically I'm modelling multiple voltage pulses so you have these ODEs which are running and then every 10ms, a new stimulus comes and resets everything back again. Now because the whole thing depends on varying ion flow which changes over time (modelled in the ODEs), you won't see exactly the same behaviour each time you run it.

I need the integration to stop at 10ms then re-start from that exact point with the initial conditions reset. See this picture for an example of what I want !
http://capocaccia.ethz.ch/capo/attachment/wiki/2010/spinn10/LIF%20Model%20-%20Input%20Neuron%20Membrane%20Potential%20%28SpiNNaker%29.png

When I just run it in a loop, the different spikes aren't connected.

Thanks

David
  

Torsten <Torsten.Hennig@umsicht.fraunhofer.de> wrote in message <95365902-308e-4364-b7ee-8ac599409d49@gi10g2000vbb.googlegroups.com>...
> On 23 Feb., 20:05, "David Cox" <dcwrite...@googlemail.com> wrote:
> > Hi,
> >
> > I have a set of ODEs modelling neuronal spiking in the brain for a period of 200ms. I'm solving this using ode45 and I now want to alter it so that the initial conditions reset every 10ms.
> >
> > I realise I need to do this using the events option (I've been looking at the BALLODE m file as an example).
> >
> > However I'm not sure what I need to set 'value' as in my 'events' function because my threshold is for time rather than the output y ?
> >
> > Below is my code....Many thanks for any help anyone can give me !!!
> >
> > t = 0:200;
> > y0 = [60;0];
> > refine = 4;
> > options = odeset('Events',@events,'OutputFcn',@odeplot,'OutputSel',1,...
> >                  'Refine',refine);
> > tout = 0;
> > yout = y0.';
> > teout = [];
> > yeout = [];
> > ieout = [];
> > for i = 1:10
> >   % Solve until the first terminal event.
> >   [t,y,te,ye,ie] = ode45(@neuron,t,y0,options);
> >   if ~ishold
> >     hold on
> >   end
> >   % Accumulate output.  .
> >   nt = length(t);
> >   tout = [tout; t(2:nt)];
> >   yout = [yout; y(2:nt,:)];
> >   teout = [teout; te];
> >   yeout = [yeout; ye];
> >   ieout = [ieout; ie];
> >
> >   ud = get(gcf,'UserData');
> >   if ud.stop
> >     break;
> >   end
> >
> >   % Set the new initial conditions
> >   y0(1) = 60;
> >   y0(2) = 0;
> >   tstart = t(nt);
> > end
> > -------------------------------------------------------------------
> > function [value,isterminal,direction] = events(t,y)
> > % Stop integration every 10s.
> >     value = ??????;
> >     isterminal = 1;   % stop the integration
> >     direction = 0;
> >
> > end
>
> I don't understand. Do your ODEs explicity depend on time ?
> Otherwise, by resetting the initial conditions to the starting
> conditions,
> you'll get the same result over and over again.
>
> Anyhow: As far as I can see, there is no need to use the events
> option.
> Just call ODE45 in a loop in which you set the start time to the old
> end time
> and the new end time to the old end time + 10 ms:
>
> tfinal = 200;
> deltat = 10;
> nend = 20;
>
> For i = 1:nend
> [t,y] = ode45(@neuron,[(i-1)*deltat i*deltat],y0,options);
> ...
> [Store solution at time i*deltat and reset initial conditions]
> ...
> end
>
> Best wishes
> Torsten.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
ode45 David 23 Feb, 2012 14:09:16
events David 23 Feb, 2012 14:09:16
time threshold David 23 Feb, 2012 14:09:16
events time thresh... David 23 Feb, 2012 14:09:16
reset time David 23 Feb, 2012 14:09:16
rssFeed for this Thread

Contact us