Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
random discontinuities in dde23

Subject: random discontinuities in dde23

From: Erida Gjini

Date: 13 Jun, 2008 11:48:01

Message: 1 of 9

How can I program a system of differential delay equations,
whose number depends on a random variable? So the number of
equations can change at random times during the
simulation... I have tried to use Jumps and the history =sol
options, but it doesn't work. The main problem is how to
handle the fact that discontinuities will arise at random
times and their total number is also not known beforehand.
Thanks for your help!

Subject: random discontinuities in dde23

From: Jacek Kierzenka

Date: 13 Jun, 2008 13:32:00

Message: 2 of 9

If the number of equations changes, you will need to restart the solver.
Have you tried using the Events option to stop the simulation at an event
and then restarting?

Regards,
Jacek

--------------------

"Erida Gjini" <0229156@students.uu.nl> wrote in message
news:g2tmph$558$1@fred.mathworks.com...
> How can I program a system of differential delay equations,
> whose number depends on a random variable? So the number of
> equations can change at random times during the
> simulation... I have tried to use Jumps and the history =sol
> options, but it doesn't work. The main problem is how to
> handle the fact that discontinuities will arise at random
> times and their total number is also not known beforehand.
> Thanks for your help!

Subject: random discontinuities in dde23

From: Erida Gjini

Date: 13 Jun, 2008 14:55:03

Message: 3 of 9

Thanks for the answer. I am trying to implement the option
with Events. I still don't know how to include the fact that
my events change the state of the system. Do I put that in
the events function file?
So in case event x (e.g. some random number =1 instead of 0)
is terminal, then stop integration, change the state of the
system and continue?
Regards,
Erida






"Jacek Kierzenka" <Jacek.Kierzenka@mathworks.com> wrote in
message <g2tssh$mgv$1@ginger.mathworks.com>...
> If the number of equations changes, you will need to
restart the solver.
> Have you tried using the Events option to stop the
simulation at an event
> and then restarting?
>
> Regards,
> Jacek
>
> --------------------
>
> "Erida Gjini" <0229156@students.uu.nl> wrote in message
> news:g2tmph$558$1@fred.mathworks.com...
> > How can I program a system of differential delay equations,
> > whose number depends on a random variable? So the number of
> > equations can change at random times during the
> > simulation... I have tried to use Jumps and the history =sol
> > options, but it doesn't work. The main problem is how to
> > handle the fact that discontinuities will arise at random
> > times and their total number is also not known beforehand.
> > Thanks for your help!
>
>

Subject: random discontinuities in dde23

From: Jacek Kierzenka

Date: 13 Jun, 2008 17:35:43

Message: 4 of 9

To clarify -- what I had in mind was:
  Stop, change the state, restart the solver (from the new state, but
perhaps using the previous solution as history function...)

Hope that works for you,

Jacek

------------------
"Erida Gjini" <0229156@students.uu.nl> wrote in message
news:g2u1o7$90p$1@ginger.mathworks.com...
> Thanks for the answer. I am trying to implement the option
> with Events. I still don't know how to include the fact that
> my events change the state of the system. Do I put that in
> the events function file?
> So in case event x (e.g. some random number =1 instead of 0)
> is terminal, then stop integration, change the state of the
> system and continue?
> Regards,
> Erida
>
>
>
>
>
>
> "Jacek Kierzenka" <Jacek.Kierzenka@mathworks.com> wrote in
> message <g2tssh$mgv$1@ginger.mathworks.com>...
>> If the number of equations changes, you will need to
> restart the solver.
>> Have you tried using the Events option to stop the
> simulation at an event
>> and then restarting?
>>
>> Regards,
>> Jacek
>>
>> --------------------
>>
>> "Erida Gjini" <0229156@students.uu.nl> wrote in message
>> news:g2tmph$558$1@fred.mathworks.com...
>> > How can I program a system of differential delay equations,
>> > whose number depends on a random variable? So the number of
>> > equations can change at random times during the
>> > simulation... I have tried to use Jumps and the history =sol
>> > options, but it doesn't work. The main problem is how to
>> > handle the fact that discontinuities will arise at random
>> > times and their total number is also not known beforehand.
>> > Thanks for your help!
>>
>>
>

Subject: random discontinuities in dde23

From: Steven Lord

Date: 14 Jun, 2008 02:38:43

Message: 5 of 9


"Erida Gjini" <0229156@students.uu.nl> wrote in message
news:g2u1o7$90p$1@ginger.mathworks.com...
> Thanks for the answer. I am trying to implement the option
> with Events. I still don't know how to include the fact that
> my events change the state of the system. Do I put that in
> the events function file?
> So in case event x (e.g. some random number =1 instead of 0)
> is terminal, then stop integration, change the state of the
> system and continue?

Look at the BALLODE demo example. That uses an events function to determine
when to stop one run of one of the ODE solvers, then generates a new set of
initial conditions from the last result of the previous run and starts a new
run of the ODE solver using the new initial conditions.

You should be able to modify this to use the DDE23 delay-differential
equation solver.

--
Steve Lord
slord@mathworks.com

Subject: random discontinuities in dde23

From: Erida Gjini

Date: 15 Jun, 2008 19:26:02

Message: 6 of 9

Thanks for the suggestion. I looked at the BALLODE example
and I have modified it to fit my dde problem:
.
.
.
.
for i=1:10
sol= dde23(@f,tau,history,[tstart tfinal],options);
t=sol.x;
y=sol.y;
te=sol.xe;
ye=sol.ye;
ie=sol.ie;
.
.
.
My events are random events that may or may not depend on
the solution at time t. The are all terminal if a random
number is 1 and nonterminal otherwise. Each event changes
one of the variables in the system by increasing it from
zero to some nonzero value. So I use the solution up to each
terminal event as history for next iteration, and the new
value for the history of the changing variable.

I get the following error though:

Error in ==> dde23 at 310
  valt = feval(events,t0,y0,Z0,varargin{:});

which doesn't allow the solution to be computed.
Even if I set the probability of the events to zero, aiming
to get zero events, so straightforward computation, the same
error persists.
 
Any ideas?
Thanks in advance,
Erida

Subject: random discontinuities in dde23

From: Jacek Kierzenka

Date: 16 Jun, 2008 13:55:51

Message: 7 of 9

This suggests a problem with evaluating the Events function -- but you do
not show the full error message.
Could you provide the error message? And/or your Events function?

Thanks,
Jacek
---------------------------------------

"Erida Gjini" <0229156@students.uu.nl> wrote in message
news:g33qca$nqt$1@fred.mathworks.com...
> Thanks for the suggestion. I looked at the BALLODE example
> and I have modified it to fit my dde problem:
> .
> .
> .
> .
> for i=1:10
> sol= dde23(@f,tau,history,[tstart tfinal],options);
> t=sol.x;
> y=sol.y;
> te=sol.xe;
> ye=sol.ye;
> ie=sol.ie;
> .
> .
> .
> My events are random events that may or may not depend on
> the solution at time t. The are all terminal if a random
> number is 1 and nonterminal otherwise. Each event changes
> one of the variables in the system by increasing it from
> zero to some nonzero value. So I use the solution up to each
> terminal event as history for next iteration, and the new
> value for the history of the changing variable.
>
> I get the following error though:
>
> Error in ==> dde23 at 310
> valt = feval(events,t0,y0,Z0,varargin{:});
>
> which doesn't allow the solution to be computed.
> Even if I set the probability of the events to zero, aiming
> to get zero events, so straightforward computation, the same
> error persists.
>
> Any ideas?
> Thanks in advance,
> Erida
>
>
>

Subject: random discontinuities in dde23

From: Erida Gjini

Date: 16 Jun, 2008 15:02:02

Message: 8 of 9

Thanks Jacek, I solved the previous problem by including the
delay in the input parameters of my events function so
events(t,y,D)... had forgotten to do it before. I get a
reasonable simulation now, but there are some issues that
maybe you can help with:

1) is there a way to set Nonnegativity to variables in dde23?

2) how important is the max in the i loop (BALLODE demo)
for i=1:max
sol=dde23...
when i don't know in advance how many random events will
happen? In the BALLODE example, we set max =10 because we
want to compute the first 10 bounces, but in a more general
case, how can I set the max index for i? Maybe between
tstart and tfinal there are 4 events (mutants arising
according to some Poisson process) or 1 event, or 6 events...

3) All simulation runs are incomplete in the sense that I
get an error when time is up, saying:

??? Error using ==> dde23 at 103
Must have tspan(1) < tspan(end).
I think it has to do with the i-loop and the fact that maybe
the max nr. of events is not reached. Any ideas?

4) How can I get a better plot, instead of the points at
each timestep used by the solver, a suitable line for example?

5) Final question (I hope): what is a good way to control
the step size in this case? My computations seem pretty slow
and memory consuming...

Thanks a lot for your help,
Erida


"Jacek Kierzenka" <Jacek.Kierzenka@mathworks.com> wrote in
message <g35rd7$m14$1@fred.mathworks.com>...
> This suggests a problem with evaluating the Events
function -- but you do
> not show the full error message.
> Could you provide the error message? And/or your Events
function?
>
> Thanks,
> Jacek
> ---------------------------------------
>
> "Erida Gjini" <0229156@students.uu.nl> wrote in message
> news:g33qca$nqt$1@fred.mathworks.com...
> > Thanks for the suggestion. I looked at the BALLODE example
> > and I have modified it to fit my dde problem:
> > .
> > .
> > .
> > .
> > for i=1:10
> > sol= dde23(@f,tau,history,[tstart tfinal],options);
> > t=sol.x;
> > y=sol.y;
> > te=sol.xe;
> > ye=sol.ye;
> > ie=sol.ie;
> > .
> > .
> > .
> > My events are random events that may or may not depend on
> > the solution at time t. The are all terminal if a random
> > number is 1 and nonterminal otherwise. Each event changes
> > one of the variables in the system by increasing it from
> > zero to some nonzero value. So I use the solution up to each
> > terminal event as history for next iteration, and the new
> > value for the history of the changing variable.
> >
> > I get the following error though:
> >
> > Error in ==> dde23 at 310
> > valt = feval(events,t0,y0,Z0,varargin{:});
> >
> > which doesn't allow the solution to be computed.
> > Even if I set the probability of the events to zero, aiming
> > to get zero events, so straightforward computation, the same
> > error persists.
> >
> > Any ideas?
> > Thanks in advance,
> > Erida
> >
> >
> >
>
>

Subject: random discontinuities in dde23

From: Jacek Kierzenka

Date: 16 Jun, 2008 16:10:04

Message: 9 of 9

Good questions!

1) Unfortunately no. Currently, the 'Nonnegative' option is not supported in
DDE23.

2) It may not be important for your problem -- while-loop with a reasonable
stopping criteria will probably do.

3) Not sure about this one. Try displaying the value of tspan before calling
the solver, and see if that condition is satisfied...

4) The structure 'sol' stores enough information to produce a continuous
(interpolated) solution.
Use DEVAL: yinterp = deval(sol,xinterp), for any sol.x(1) <= xinterp <=
sol.x(end)

5) DDE23 is a variable step solver -- the only thing you could do is to try
relaxing the tolerances (AbsTol and RelTol)

Good luck,
Jacek

------------------------

"Erida Gjini" <0229156@students.uu.nl> wrote in message
news:g35v9a$ems$1@fred.mathworks.com...
> Thanks Jacek, I solved the previous problem by including the
> delay in the input parameters of my events function so
> events(t,y,D)... had forgotten to do it before. I get a
> reasonable simulation now, but there are some issues that
> maybe you can help with:
>
> 1) is there a way to set Nonnegativity to variables in dde23?
>
> 2) how important is the max in the i loop (BALLODE demo)
> for i=1:max
> sol=dde23...
> when i don't know in advance how many random events will
> happen? In the BALLODE example, we set max =10 because we
> want to compute the first 10 bounces, but in a more general
> case, how can I set the max index for i? Maybe between
> tstart and tfinal there are 4 events (mutants arising
> according to some Poisson process) or 1 event, or 6 events...
>
> 3) All simulation runs are incomplete in the sense that I
> get an error when time is up, saying:
>
> ??? Error using ==> dde23 at 103
> Must have tspan(1) < tspan(end).
> I think it has to do with the i-loop and the fact that maybe
> the max nr. of events is not reached. Any ideas?
>
> 4) How can I get a better plot, instead of the points at
> each timestep used by the solver, a suitable line for example?
>
> 5) Final question (I hope): what is a good way to control
> the step size in this case? My computations seem pretty slow
> and memory consuming...
>
> Thanks a lot for your help,
> Erida
>
>
> "Jacek Kierzenka" <Jacek.Kierzenka@mathworks.com> wrote in
> message <g35rd7$m14$1@fred.mathworks.com>...
>> This suggests a problem with evaluating the Events
> function -- but you do
>> not show the full error message.
>> Could you provide the error message? And/or your Events
> function?
>>
>> Thanks,
>> Jacek
>> ---------------------------------------
>>
>> "Erida Gjini" <0229156@students.uu.nl> wrote in message
>> news:g33qca$nqt$1@fred.mathworks.com...
>> > Thanks for the suggestion. I looked at the BALLODE example
>> > and I have modified it to fit my dde problem:
>> > .
>> > .
>> > .
>> > .
>> > for i=1:10
>> > sol= dde23(@f,tau,history,[tstart tfinal],options);
>> > t=sol.x;
>> > y=sol.y;
>> > te=sol.xe;
>> > ye=sol.ye;
>> > ie=sol.ie;
>> > .
>> > .
>> > .
>> > My events are random events that may or may not depend on
>> > the solution at time t. The are all terminal if a random
>> > number is 1 and nonterminal otherwise. Each event changes
>> > one of the variables in the system by increasing it from
>> > zero to some nonzero value. So I use the solution up to each
>> > terminal event as history for next iteration, and the new
>> > value for the history of the changing variable.
>> >
>> > I get the following error though:
>> >
>> > Error in ==> dde23 at 310
>> > valt = feval(events,t0,y0,Z0,varargin{:});
>> >
>> > which doesn't allow the solution to be computed.
>> > Even if I set the probability of the events to zero, aiming
>> > to get zero events, so straightforward computation, the same
>> > error persists.
>> >
>> > Any ideas?
>> > Thanks in advance,
>> > Erida
>> >
>> >
>> >
>>
>>
>

Tags for this Thread

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.

Contact us