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:
dde23: getting the actual step-size at each integration point

Subject: dde23: getting the actual step-size at each integration point

From: Erida Gjini

Date: 27 Jun, 2008 13:37:03

Message: 1 of 5

Hi,
I am having a problem with dde23. I wanted to use the actual
step-size used by the solver at each integration time-step,
to calculate a new variable dependent on it. I noticed
though that it happens sometimes that this step-size is
negative, meaning that time instead of only increasing
during integration, decreases at specific instances... like
0 0.004, 0.012, 0.340, 0.190, 0.403,....

Is this possible in the way dde23 works? I use an events
function and I use the actual dt inside it, to determine
whether an event happens or not. Is that a possible cause of
the problem?

My way of achieving the actual step-size is by saving all
time-points calculated by the solver in an array:

tout=[tout;t]; % already here I see that the sequence is not
always increasing...

all_dt=diff(tout);
this_dt=all_dt(end); % sometimes gives me negative entries

I hope someone can help,
Thanks in advance,
Erida

Subject: dde23: getting the actual step-size at each integration point

From: Steven Lord

Date: 27 Jun, 2008 14:18:32

Message: 2 of 5


"Erida Gjini" <0229156@students.uu.nl> wrote in message
news:g42qdv$lre$1@fred.mathworks.com...
> Hi,
> I am having a problem with dde23. I wanted to use the actual
> step-size used by the solver at each integration time-step,
> to calculate a new variable dependent on it. I noticed
> though that it happens sometimes that this step-size is
> negative, meaning that time instead of only increasing
> during integration, decreases at specific instances... like
> 0 0.004, 0.012, 0.340, 0.190, 0.403,....

That's correct. Roughly, DDE23 tries to use the solution at one time t0 to
generate the solution at a future time t1. However, if it can't do so in
such a way that it achieves the requested accuracy, it rejects the solution
it generated at t1 and chooses a new time, t1', that's between t0 and t1 and
tries to generate the solution at t1', repeating until it gets an accurate
solution at some t1'. It then uses that as the new t0 for generating a
solution at a new t1. Those rejection steps are why the vector of times at
which your function was evaluated is not monotonic.

> Is this possible in the way dde23 works? I use an events
> function and I use the actual dt inside it, to determine
> whether an event happens or not. Is that a possible cause of
> the problem?

Can you describe in more detail why you need to use dt to determine if an
event occurs? Can you use t instead, since it is passed into the events
function?

*snip*

--
Steve Lord
slord@mathworks.com

Subject: dde23: getting the actual step-size at each integration point

From: Erida Gjini

Date: 27 Jun, 2008 14:52:02

Message: 3 of 5

Suppose events occur with rate M*dt (in some dde system)
where M depends on the state of the system at time t. They
change the state of the system by the fact that an event
introduces a new subpopulation. Now at each integration time
point I am tossing a coin to determine whether an event
occurs or not. I am using a binomial random variable for this:

...in the events function:

value = 1-binornd(1,M*dt);

the problem is dt is not constant, so I have to get it from
the solver step-size... Any ideas or suggestions?

Maybe on a more general setting the question is: how to
combine a dde system with a Poisson (density-dependent rate
) random process?

Thanks for the reply,
Erida









"Steven Lord" <slord@mathworks.com> wrote in message
<g42sro$k38$1@fred.mathworks.com>...
>
> "Erida Gjini" <0229156@students.uu.nl> wrote in message
> news:g42qdv$lre$1@fred.mathworks.com...
> > Hi,
> > I am having a problem with dde23. I wanted to use the actual
> > step-size used by the solver at each integration time-step,
> > to calculate a new variable dependent on it. I noticed
> > though that it happens sometimes that this step-size is
> > negative, meaning that time instead of only increasing
> > during integration, decreases at specific instances... like
> > 0 0.004, 0.012, 0.340, 0.190, 0.403,....
>
> That's correct. Roughly, DDE23 tries to use the solution
at one time t0 to
> generate the solution at a future time t1. However, if it
can't do so in
> such a way that it achieves the requested accuracy, it
rejects the solution
> it generated at t1 and chooses a new time, t1', that's
between t0 and t1 and
> tries to generate the solution at t1', repeating until it
gets an accurate
> solution at some t1'. It then uses that as the new t0 for
generating a
> solution at a new t1. Those rejection steps are why the
vector of times at
> which your function was evaluated is not monotonic.
>
> > Is this possible in the way dde23 works? I use an events
> > function and I use the actual dt inside it, to determine
> > whether an event happens or not. Is that a possible cause of
> > the problem?
>
> Can you describe in more detail why you need to use dt to
determine if an
> event occurs? Can you use t instead, since it is passed
into the events
> function?
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
>
>

Subject: dde23: getting the actual step-size at each integration point

From: Sarah

Date: 9 Sep, 2013 20:49:07

Message: 4 of 5

Hi -

Is there was a way to make it so if dde23 takes a certain period of time picking these adaptive steps (say 2 seconds), it will return with a flag or error instead of just infinitely picking time steps?

"Erida Gjini" <0229156@students.uu.nl> wrote in message <g42qdv$lre$1@fred.mathworks.com>...
> Hi,
> I am having a problem with dde23. I wanted to use the actual
> step-size used by the solver at each integration time-step,
> to calculate a new variable dependent on it. I noticed
> though that it happens sometimes that this step-size is
> negative, meaning that time instead of only increasing
> during integration, decreases at specific instances... like
> 0 0.004, 0.012, 0.340, 0.190, 0.403,....
>
> Is this possible in the way dde23 works? I use an events
> function and I use the actual dt inside it, to determine
> whether an event happens or not. Is that a possible cause of
> the problem?
>
> My way of achieving the actual step-size is by saving all
> time-points calculated by the solver in an array:
>
> tout=[tout;t]; % already here I see that the sequence is not
> always increasing...
>
> all_dt=diff(tout);
> this_dt=all_dt(end); % sometimes gives me negative entries
>
> I hope someone can help,
> Thanks in advance,
> Erida
>
>

Subject: dde23: getting the actual step-size at each integration point

From: Nasser M. Abbasi

Date: 10 Sep, 2013 02:54:29

Message: 5 of 5

On 9/9/2013 3:49 PM, Sarah wrote:
> Hi -
>
> Is there was a way to make it so if dde23 takes a certain period of
>time picking these adaptive steps (say 2 seconds), it will return with a
>flag or error instead of just infinitely picking time steps?
>

You can't directly control the step size taken by these numerical
integrators, but you can specify what error you are willing to
tolerate at each step, and this will influence the step size.

http://www.mathworks.com/help/matlab/ref/ddeset.html

"Error Control Properties

At each step, the DDE solvers estimate an error e. The
dde23 function estimates the local truncation error, and the
other solvers estimate the residual. In either case, this error
must be less than or equal to the acceptable error"

So, if you increase ReTol, this should make the step size
larger. But I have not tried these myself. You can try and see.
also check the NormControl option.

"The estimated error in each integration step satisfies |e(i)|max(RelTol*abs(y(i)),AbsTol(i))"

--Nasser

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