I am trying to figure out how to get the solution curve to an NDSolve to slide along once it reaches a boundary and then to exit the CrossSlidingDiscontinuity once it reaches an equilbrium curve and follow the equilibrium curve back within a set boundary.

If the x[t] solution curve reaches the boundary edge on this interval [0,1] I needed it to slide along this boundary, hence I used CrossSlidingDiscontinuity. However once, the solution reaches the yellow equilibrium sine curve, I need it to exit the sliding discontinuity and follow the equilibrium curve. I tried using EventLocator (in the code below). It manages to fall back within [0,1] but does not follow the equilibrium sine curve. I attached the image of the plot below.

I also tried using two WhenEvents (one for when x[t] reaches 1 triggering the sliding and one where x[t] reaches the sine curve triggering to follow the sine curve) but only the sliding WhenEvent was triggered.

Here is my code:

normalDE2[x_, t_] := -(x + 1/2)*(x - 1/2)*(x - (1 + .1*Sin[t]));

testDE3[x_?NumberQ, t_] := 
If[0 < x < 1, normalDE2[x, t], -1*normalDE2[x, t]];

sol4 = NDSolve[{x'[t] == testDE3[x[t], t], x[0] == .75, 
WhenEvent[{x[t] == 1, x[t] == 0}, 
x, {t, 0, 10},
Method -> {"EventLocator", "Event" -> {x[t] - (1 +.1*Sin[t])},
"EventAction" :> {{x[t] -> (1 + .1*Sin[t])}}}];

Plot[{x[t] /. sol4, (1 + .1*Sin[t])}, {t, 0, 10}, 
Frame -> True, GridLines -> Automatic] 

Plot ImagePlot Image

  • $\begingroup$ I solved your problem in a different way (similar to here), and got the same result. You say the (blue) solution doesn't follow the (yellow) equilibrium curve. I think it is following it, but with a lag so that it isn't perfectly equilibrated. If you don't want that lag, multiply the right hand side of x'[t] by 1000. $\endgroup$
    – Chris K
    Jul 20, 2020 at 22:07
  • $\begingroup$ That helped a lot, thanks! @ChrisK $\endgroup$
    – user
    Jul 22, 2020 at 4:29


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.