From: Luca Cerone on
Dear all,
I'm trying to simulate a systems where certain condition "trigger" different behaviour
and before of making mistakes I'd like to know if you have advices on how to deal
with such a situation:

dydt=odefun(t,y)
a=1;
b=1;
signal=sin(t)+1;
threshold=1;
dydt = a*(signal >= threshold) - b ;
end

This is just a minimal example to let you understand sort of what I'd like to simulate:
basically I have a certain signal that gives an input to y if it's above a certain threshold
and remove the input if it's below.

Checking on the newsgroup I've found that some of you have suggested the use of a Stiffness Matrix and of the Event option of the ode solver, but it's really
not so clear to me how these should be work.

If you've dealt with discontinuities may you please give me some hints?
Thank you very much!
Cheers, -Luca
From: Steven_Lord on


"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message
news:i3rcfg$3pg$1(a)fred.mathworks.com...
> Dear all,
> I'm trying to simulate a systems where certain condition "trigger"
> different behaviour
> and before of making mistakes I'd like to know if you have advices on how
> to deal
> with such a situation:
>
> dydt=odefun(t,y)
> a=1;
> b=1;
> signal=sin(t)+1;
> threshold=1;
> dydt = a*(signal >= threshold) - b ;
> end
>
> This is just a minimal example to let you understand sort of what I'd like
> to simulate:
> basically I have a certain signal that gives an input to y if it's above a
> certain threshold
> and remove the input if it's below.
>
> Checking on the newsgroup I've found that some of you have suggested the
> use of a Stiffness Matrix and of the Event option of the ode solver, but
> it's really
> not so clear to me how these should be work.
>
> If you've dealt with discontinuities may you please give me some hints?
> Thank you very much!
> Cheers, -Luca

Look at the BALLODE demo. That demo simulates a bouncing ball; when the
position of the ball reaches a threshold of 0 (aka the floor) the events
function stops the solver, then the demo uses the last results from the
solver to generate new initial conditions and starts solving again from that
point with the new initial conditions. You should be able to do something
similar; you're just heading for the ceiling instead of the floor.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: Luca Cerone on
Hi Steve,
thanks for pointing me at the right direction (yes I guess that with a few modification
this would be exactly what I'm looking for), though I can't really understand
how to use the events.. as far as I've understood, the events only
allows me to specify if a certain value passes through 0 right?
So, saying I want to "trigger" the event when a certain function f(t)
passes through a certain threshold th I should have to consider the function
g=f(t)-th right?
Hope I can make it work!
Thanks a lot, by the way :)
Cheers, -Luca

>
> Look at the BALLODE demo. That demo simulates a bouncing ball; when the
> position of the ball reaches a threshold of 0 (aka the floor) the events
> function stops the solver, then the demo uses the last results from the
> solver to generate new initial conditions and starts solving again from that
> point with the new initial conditions. You should be able to do something
> similar; you're just heading for the ceiling instead of the floor.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
From: Luca Cerone on
I went through the documentation,
but it is not very clear to me what the IE variable received in output is.
Also I couldn't really understand how to get information
about the directionality. In order to change the values in my ODE I need to know
if the signal is going above or below the threshold.
Can someone help me understanding that?
Cheers, -Luca
> >
> > Look at the BALLODE demo. That demo simulates a bouncing ball; when the
> > position of the ball reaches a threshold of 0 (aka the floor) the events
> > function stops the solver, then the demo uses the last results from the
> > solver to generate new initial conditions and starts solving again from that
> > point with the new initial conditions. You should be able to do something
> > similar; you're just heading for the ceiling instead of the floor.
> >
> > --
> > Steve Lord
> > slord(a)mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> > To contact Technical Support use the Contact Us link on
> > http://www.mathworks.com
From: Steven_Lord on


"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message
news:i3tsev$m1q$1(a)fred.mathworks.com...
> I went through the documentation,
> but it is not very clear to me what the IE variable received in output is.

If your events function returns a vector for the value (first) output, and
one of those values crossed 0 [thus triggering an event] the IE variable
will indicate which element of the value vector crossed 0. For example, if
you were modeling a ball falling from far enough, your events function might
want to monitor two things: the height of the ball and its velocity. If
the height reaches 0, the ball's hit the ground and you want to handle that
event one way. If the velocity reaches the ball's terminal velocity, then
you might want to either note it or change how you model the ball's fall.
It's kind of important to know which of those two events occurred, as
they're quite different circumstances.

> Also I couldn't really understand how to get information
> about the directionality. In order to change the values in my ODE I need
> to know
> if the signal is going above or below the threshold.
> Can someone help me understanding that?

That's what the third output of the events function is for. If you return 0
for that output, MATLAB will trigger an event if the signal crosses 0 either
increasing or decreasing. If you return +1 it only triggers an event if the
signal is increasing, and for -1 only if the signal is decreasing. You can
also look at the t and y outputs of the ODE -- they will contain the value
of the signal up until the point where the event caused the solver to
terminate.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com