1
$\begingroup$

MSE ode coupled question

What is a better way to code using Mathematica in my answer in order to visualize a dynamic situation between given $(x,y)$ field limits for several starting curves/points?

I shall link your replies there.

$\endgroup$

1 Answer 1

2
$\begingroup$

Update: You can control (move / remove / add) initial values dynamically using Locators as in, for example, this answer.

tm = 15;
EQ1[a_, b_] := {X'[t] == X[t] (1 - Y[t]),  Y'[t] == 1 + Y[t] (X[t] - 1), 
   X[0] == a, Y[0] == b};
pf = ParametricNDSolveValue[EQ1[a, b], {X, Y}, {t, 0, tm}, {a, b}];

ab = {{- 0.4, 2.75}, {-.2, 4}, {4.4, 3.75}};

manipulate = Manipulate[
  ParametricPlot[Evaluate[Table[Through@pf[a[[1]], a[[2]]][t], {a, u}]], {t, 0, tm}, 
     GridLines -> Automatic, AspectRatio -> 1, PlotRange -> All,
     BaseStyle -> Thick, Frame -> True, 
     Epilog -> ListPlot[{Labeled[#, Style[#, 16, "Panel"]]} & /@ u, 
        PlotStyle -> PointSize[Large]][[1]]],
   {{u, ab}, Locator, Appearance -> None, LocatorAutoCreate -> True}];

Evaluate the following line in place, i.e. highlight it and use Ctrl+Shift+Enter

DynamicSetting[manipulate]

enter image description here

To print the current snapshot in the next cell use Shift+Enter:

enter image description here

Original answer:

You might find ParametricNDSolveValue convenient:

tm = 10;
EQ1[a_, b_] := {X'[t] == X[t] (1 - Y[t]),  Y'[t] == 1 + Y[t] (X[t] - 1), 
  X[0] == a, Y[0] == b};
pf = ParametricNDSolveValue[EQ1[a, b], {X, Y}, {t, 0, tm}, {a, b}];

ab = {{- 0.4, 2.75}, {-.2, 4}, {4.4, 3.75}};

ParametricPlot[Evaluate[Table[Through @ pf[a[[1]], a[[2]]][t], {a, ab}]], {t, 0, tm}, 
 GridLines -> Automatic, AspectRatio -> 1, PlotRange -> All, BaseStyle -> Thick,
 Epilog -> ListPlot[Labeled[#, Style[#, 16, "Panel"]] & /@ ab, 
  PlotStyle -> PointSize[Large]][[1]]]

enter image description here

colors = Partition[ColorData[63, "ColorList"][[;; 6]], 2];
Table[cf[ab[[i]]] = colors[[i]], {i, Length@ab}];

Show[Table[Plot[Evaluate[Through@pf[a[[1]], a[[2]]][t]], {t, 0, tm},
  BaseStyle -> Thick, PlotStyle -> cf[a], 
  PlotLegends -> (TraditionalForm /@ ({X[##][t], Y[##][t]} & @@ a))], {a, ab}]]

enter image description here

$\endgroup$

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.