0
$\begingroup$

I am trying to plot with the following code

B = -2; A = 1;
s = ParametricNDSolveValue[{Sqrt[-1]*x'[t] == 
B*x[t] - R*x[t]*Abs[x[t]]^2 - A*y[t], x[0] == 1, 
Sqrt[-1]*y'[t] == B*y[t] - R*y[t]*Abs[y[t]]^2 - A*x[t], 
y[0] == -1}, {x, y}, {t, 0, 100}, {R}];
coll = {};
Table[pp = 
ParametricPlot[Re@Through[s[a][t]], {t, 0, 100}, 
PlotRange -> {{-2, 2}, {-2, 2}}, PerformanceGoal -> "Quality", 
MeshFunctions -> (#2 &), Mesh -> {{0.}}, 
MeshStyle -> {Red, PointSize[0.01]}];
pts = pp[[1, 1]];
AppendTo[
coll, {a, #[[1]]} & /@ 
pts[[First@Cases[pp[[1]], Point[x__] :> x, -1]]]];, {a, 0.0, 5, 
0.01}];
lp = ListPlot[Join @@ coll, Frame -> True, PlotStyle -> Red];
Manipulate[
Column[{ParametricPlot[Re@Through[s[par][t]], {t, 0, 100}, 
PlotRange -> {{-2, 2}, {-2, 2}}, PerformanceGoal -> "Quality", 
MeshFunctions -> (#2 &), Mesh -> {{0.}}, 
MeshStyle -> {Red, PointSize[0.01]}, Frame -> True, 
FrameLabel -> {"x[t]", "y[t]"}], 
Show[lp, Graphics[{Gray, Line[{{par, 0}, {par, 4}}]}]]}], {par, 
0.0, 5, 0.01}]

I want to manipulate for more than one parameter, In the code I have to then replace R with any other parameter I want to manipulate with. I want to manipulate for all parameters A,B,R with a range from, say 0 to 100. The solution part goes without error, but the plot part starting at coll={} gives errors even though I tried to increase the number of parameters. I tried for one extra manipulating parameter and amended the code as

coll = {};
Table[pp = 
ParametricPlot[Re@Through[s[a][b][t]], {t, 0, 20}, 
PlotRange -> {{-2, 2}, {-2, 2}}, PerformanceGoal -> "Quality", 
MeshFunctions -> (#2 &), Mesh -> {{0.}}, 
MeshStyle -> {Red, PointSize[0.01]}];
pts = pp[[1, 1]];
AppendTo[
coll, {a, b, #[[1]]} & /@ 
pts[[First@Cases[pp[[1]], Point[x__] :> x, -1]]]];, {a, 0.0, 5, 
0.01}, {b, 0.0, 5, 0.01}];
lp = ListPlot[Join @@ coll, Frame -> True, PlotStyle -> Red];
Manipulate[
Column[{ParametricPlot[Re@Through[s[par1][par2][t]], {t, 0, 20}, 
PlotRange -> {{-2, 2}, {-2, 2}}, PerformanceGoal -> "Quality", 
MeshFunctions -> (#2 &), Mesh -> {{0.}}, 
MeshStyle -> {Red, PointSize[0.01]}, Frame -> True, 
FrameLabel -> {"x[t]", "y[t]"}], 
Show[lp, 
Graphics[{Gray, 
  Line[{{par1, 0}, {par1, 4}, {par2, 0}, {par2, 4}}]}]]}], {par1, 
0.0, 5, 0.01}, {par2, 0.0, 5, 0.01}]

It gives error messages.

$\endgroup$
  • $\begingroup$ What errors? I can't reproduce any error messages. Have you tried reducing your example to narrow the problem down? $\endgroup$ – Kuba Jul 17 '18 at 5:43
  • $\begingroup$ @Kuba Yes the code works, but problem occurs when I am trying to put more than one parameters in Manipulate, as i mentioned in the second code above. $\endgroup$ – AtoZ Jul 17 '18 at 10:27
  • 1
    $\begingroup$ @JānisŠmits Right. The second part however does not return errors, if instead we choose the initial conditions as x[0]=1,y[0]=0 or x[0]=0,y[0]=1 or with -1. and a single Manipulate parameter, as mentioned in the first code. But the error seems to pop up somehow when choosing antisymmetric initial conditions x[0]=1,y[0]=-1 or x[0]=-1,y[0]=1. $\endgroup$ – AtoZ Jul 17 '18 at 13:11
  • 1
    $\begingroup$ I am unsure what this line does: AppendTo[ coll, {a, b, #[[1]]} & /@ pts[[First@Cases[pp[[1]], Point[x__] :> x, -1]]]];, {a, 0.0, 5, 0.01}, {b, 0.0, 5, 0.01}]; But one error you made is not redefining the s function to have multiple parameters. Here I am sweeping values of A and B: $\endgroup$ – Jānis Šmits Jul 17 '18 at 13:40
  • 1
    $\begingroup$ R = 1. s = ParametricNDSolveValue[{Sqrt[-1]*x'[t] == B*x[t] - R*x[t]*Abs[x[t]]^2 - A*y[t], x[0] == 1, Sqrt[-1]*y'[t] == B*y[t] - R*y[t]*Abs[y[t]]^2 - A*x[t], y[0] == -1}, {x, y}, {t, 0, 100}, {A, B}]; derp = Table[ pp = ParametricPlot[Re@Through[s[a, b][t]], {t, 0, 20}, PlotRange -> {{-2, 2}, {-2, 2}}, PerformanceGoal -> "Quality", MeshFunctions -> (#2 &), Mesh -> {{0.}}, MeshStyle -> {Red, PointSize[0.01]}], {a, 0, 5, 1.}, {b, 0., 5., 1.}]; $\endgroup$ – Jānis Šmits Jul 17 '18 at 13:40

Your Answer

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

Browse other questions tagged or ask your own question.