0
$\begingroup$

I am plotting a bifurcation diagram for my system with A on x-axis following the code in, How to make a bifurcation diagram of the Lorenz system under a varying parameter value?. But I get an empty output

res = Internal`Bag[];(*a place to store results*)tmax = 10;(*how long \
to run for each A value*){x0, y0} = {0, 1};(*initial ICs*)
\[Omega] = -2.5; \[Tau] = 1; Do[
sol = NDSolve[{Sqrt[-1]*x'[t] == \[Omega]*x[t] - 
   A*x[t]*Abs[x[t]]^2 - \[Tau]*y[t], 
 Sqrt[-1]*y'[t] == \[Omega]*y[t] - 
   A*y[t]*Abs[y[t]]^2 - \[Tau]*x[t], x[0] == x0, 
 y[0] == y0,(*save extrema of z[t]*)
 WhenEvent[x'[t] == 0, Internal`StuffBag[res, {A, x[t]}]]}, {x, 
 y}, {t, 0, tmax}][[1]];
(*save end value for next ICs*){x0, y0} = {x[tmax], y[tmax]} /. 
sol;, {A, 200, 0, -0.1}];

ListPlot[Re@Internal`BagPart[res, All], 
PlotStyle -> {Gray, Opacity[0.1], PointSize[0.001]}]

The initial conditions are flexible and can be changed for atleast generating some output, I tried with {x0,y0}={0,1} and {x0,y0}={1,1} but to no avail.

$\endgroup$

1 Answer 1

3
$\begingroup$

In the case of a complex function, we use Re[x'[t]] to select events.

res = Internal`Bag[];(*a place to store results*)
tmax = 10;(*how long to run for each A value*)
{x0, y0} = {0, 1};(*initial ICs*)
ω = -2.5; τ = 1;
 Do[
     sol = NDSolve[{I*x'[t] == ω*x[t] - 
           A*x[t]*Abs[x[t]]^2 - τ*y[t], 
         Sqrt[-1]*y'[t] == ω*y[t] - 
           A*y[t]*Abs[y[t]]^2 - τ*x[t], x[0] == x0, 
         y[0] == y0,(*save extrema of z[t]*)
         WhenEvent[Re[x'[t]] == 0, 
          Internal`StuffBag[res, {A, Re[x[t]]}]]}, {x, y}, {t, 0, 
         tmax}][[1]];
     (*save end value for next ICs*){x0, y0} = {x[tmax], y[tmax]} /. 
       sol;, {A, 200, 0, -0.1}];
Table[ListPlot[Internal`BagPart[res, All], 
  PlotStyle -> {Gray, Opacity[0.1], PointSize[0.001]}, 
  PlotRange -> op], {op, {Automatic, All}}]

fig1

$\endgroup$
7
  • $\begingroup$ Could you add a bit of text saying what the problem was? $\endgroup$
    – Chris K
    Jul 31, 2018 at 15:31
  • $\begingroup$ Secondly, could you please tell how you get the second plot? the one with thin lines on the right? $\endgroup$
    – AtoZ
    Aug 1, 2018 at 1:52
  • $\begingroup$ Lastly, The vertical axis corresponds to x[t] or x'[t]? $\endgroup$
    – AtoZ
    Aug 1, 2018 at 2:39
  • 1
    $\begingroup$ I added one line to the code that describes the construction of the figures. The figures show the real part of $x(t)$ - Re[x[t]], depending on the parameter A. $\endgroup$ Aug 1, 2018 at 5:25
  • 1
    $\begingroup$ I would prolly use the more conventional Sow[]/Reap[] instead of Internal`Bag[] for this, since this isn't in a compiled function anyway. $\endgroup$ Oct 6, 2018 at 2:44

Your Answer

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

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