2
$\begingroup$

I do not know how to incorporate an IntervalSlider in the code below in order to change the two instances of the t-domain (in the NDSolve and ParametricPlot commands). My code is an excerpt from a phase plane plotter. I have tried to use the example from the Documentation but to no avail. Can someone show how this can be done?

DynamicModule[{g = {}, p = {}, dx, dy, sol, x0, y0},
 dx := 1 - x y;  dy = x - y^3;
 sol[{dx_, dy_}, {x0_, y0_}] := {u[t], v[t]} /. 
   Quiet@First@
     NDSolve[{u'[t] == dx /. {x -> u[t], y -> v[t]}, 
       v'[t] == dy /. {x -> u[t], y -> v[t]}, u[0] == x0, v[0] == y0, 
       WhenEvent[Abs[v[t]] > 2, "StopIntegration"]}, {u, v}, {t, -10, 10},               
Method -> "StiffnessSwitching"];
 Column[{
   Dynamic@ClickPane[
     Show[
      Quiet@
       ParametricPlot[g, {t, -10, 10}, 
        PlotRange -> {{-2, 2}, {-2, 2}}, Axes -> None, Frame -> True, 
        ImageSize -> 450, PlotStyle -> Black],
      Graphics[{PointSize[Large], Point[p]}]],
     (AppendTo[g, sol[{dx, dy}, #]]; AppendTo[p, #]) &]
   }]
 ]
$\endgroup$
  • $\begingroup$ I want the IntervalSlider to change the t-values -10 and 10 in the two instances of {t,-10,10} $\endgroup$ – Stephen Aug 2 '17 at 13:49
4
$\begingroup$
DynamicModule[
    {g = {}, p = {}, dx, dy, sol, x0, y0, td = {-10, 10}}
  , dx := 1 - x y; dy = x - y^3
  ; sol[{dx_, dy_}, {x0_, y0_}] := {u[t], v[t]} /. Quiet@First@
     NDSolve[{u'[t] == dx /. {x -> u[t], y -> v[t]}, 
       v'[t] == dy /. {x -> u[t], y -> v[t]}, u[0] == x0, v[0] == y0, 
       WhenEvent[Abs[v[t]] > 2, "StopIntegration"]}, {u, v}, {t, -10, 
       10}, Method -> "StiffnessSwitching"
    ]
  ; Column[
        { ClickPane[  Dynamic@Show[Quiet @ ParametricPlot[
              g, {t, ##}, PlotRange -> {{-2, 2}, {-2, 2}}, Axes -> None 
            , Frame -> True, ImageSize -> 450, PlotStyle -> Black
          ] & @@  td, Graphics[{PointSize[Large], Point[p]}]], (AppendTo[g, 
       sol[{dx, dy}, #]]; AppendTo[p, #]) &]

   , IntervalSlider[Dynamic@td, {-10, 10}, Method -> "Push"]
   }]]

enter image description here

$\endgroup$
  • $\begingroup$ excellent solution! $\endgroup$ – Stephen Aug 2 '17 at 13:58
  • $\begingroup$ What is the role of & @@ td that follows the ParametricPlot command? $\endgroup$ – Stephen Aug 2 '17 at 20:35
  • $\begingroup$ @Stephen Take a look at Apply. Shortly foo[##]& @@ {b, a, r} evaluates to foo[b, a, r]. $\endgroup$ – Kuba Aug 2 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.