stop_cond question

I am using dsolve to integrate a system of equations, and I am using stop_cond to stop the integration when certain conditions are met.

The problem is, I want the integration to stop when condition 1 AND condition 2 are met, but when I use, for example

stop_cond=[y(t)-2,t-4]

it stops as soon as ONE of these conditions are met, not both. I want it to stop when y(t) is equal to 2 AFTER t=4, not before.

Any suggestions would be greatly appreciated!

 

Doug Meade's picture

compound stop condition

What about using the following:

stop_cond = [ (y(t)-2)*min(t-4,0), (y(t)-2)+min(t-4,0) ]

The first will be zero when either of the two terms is zero. Both will be zero only when both terms are zero. This is based on the fact that the unique solution to { x*y=0, x+y=0 } is { x=0, y=0 }. You could use any homogeneous nonsingulary linear system, but I thought the nonlinear system was actually a little clearer in how this works.

I hope this is helpful for you.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed
epostma's picture

events

Hi Thomas,

I'm not sure which version of Maple you are using, but Maple 12 has a very powerful new system replacing stop_cond, called events. It allows for expressing the type of thing that you are interested in very naturally:

dsn := dsolve([D(D(x))(t)=-x(t), x(0)=0, D(x)(0)=1], numeric, events=[[[x(t), t > 4], halt]]):
plots:-odeplot(dsn, numpoints=2000);

This will nicely plot sin(t) till 2 Pi and give you the following warning:

Warning, cannot evaluate the solution further right of 6.2831854, event #1 triggered a halt

Note that dsolve did a pretty good job of finding the value of 2 Pi, which is 6.283185308 according to evalf with the standard setting of Digits=10.

The events system also allows for much more complicated events: you can set the values of the functions you're integrating, set discrete variables used in other events et cetera. I'd recommend a look at ?dsolve,events if you have Maple 12.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}