7
$\begingroup$

I have simple diff. equation like $$\frac{dx}{dt} = rx^2 - x$$. I need to plot the bifurcation diagram for this.

There are quite a lot of question regarding bifurcation diagram plotting and code given there but issue with me is that I am not able to understand the code. Can someone provide the code with explanation with what is happening in the code. I know commands like Plot, Manipulate, NDSolve,ParametricNDSolve,Table but when they include @,#,Row,Seap and other things it goes haywire for me.

Can anyone provide the code without those terms and explain a bit.

$\endgroup$
3
  • $\begingroup$ Perhaps this would be a useful example. $\endgroup$
    – bbgodfrey
    Commented Mar 7, 2021 at 5:07
  • 1
    $\begingroup$ “but when they include @,#,Row,Seap and other things it goes haywire for me.” Then you should make a bit effort to learn the core language of Mathematica (A possible start point is here: mathematica.stackexchange.com/a/25616/1871), rather than ask others to provide you some code without these things. $\endgroup$
    – xzczd
    Commented Mar 7, 2021 at 6:27
  • $\begingroup$ @xzczd I got to know about these few days earlier only, I have started to learn about them but I think it will take a bit time to completely understand so that I can start using in my code. I earlier used matlab, everytime I see a problem, I start to think in procedural way, it will take a bit time to get used Mathematica functional approach. $\endgroup$
    – A Q
    Commented Mar 7, 2021 at 6:34

2 Answers 2

6
$\begingroup$

The easiest way is to use ContourPlot to plot where $dx/dt=0$.

ContourPlot[r x^2 - x == 0, {r, -2, 2}, {x, -4, 4}]

enter image description here

If you want to indicate stability, it's a little more complicated:

λ = D[r x^2 - x, x];
Show[
 ContourPlot[{
   ConditionalExpression[r x^2 - x, λ < 0] == 0,
   ConditionalExpression[r x^2 - x, λ > 0] == 0},
  {r, -2, 2}, {x, -4, 4},
  ContourStyle -> {{Black}, {Black, Dashed}}]
 ]

enter image description here

$\endgroup$
5
$\begingroup$

You can see the code in this post. We use the difference method to solve the differential equation $\frac{dx}{dt} = rx^2 - x$. Mathematically, the map is written

$${\displaystyle x_{n+1}=rx_{n}^{2}-x_{n}}$$

ff = Compile[{{r, _Real}}, ({r, #} &) /@ 
        Union[Drop[NestList[r # ^2 - # &, .1, 300], 100]]];

mm = Flatten[Table[ff[r], {r, 0.1, 4, 0.001}], 1];

ListPlot[mm, PlotStyle -> AbsolutePointSize[.0001], Axes -> True, 
 FrameLabel -> {"r", "N"}, Frame -> True, 
 PlotRange -> {{0, 4}, All}, ImageSize -> 500]

DSolve[{x'[t] == r*x[t]^2 - x[t]}, x[t], t]
Plot[Table[1/(r E^t - r - E^t), {r, 0.1, 1, 0.1}], {t, 0, 5}]

Other reference information:

https://demonstrations.wolfram.com/ClassicLogisticMap/

https://en.wikipedia.org/wiki/Logistic_map

$\endgroup$
6
  • $\begingroup$ Can you explain a bit what is happening in the 1st line and 2nd line of code. $\endgroup$
    – A Q
    Commented Mar 6, 2021 at 8:32
  • 1
    $\begingroup$ You made the post using that logisic map. What if it is a 2nd order equation. $\endgroup$
    – A Q
    Commented Mar 6, 2021 at 8:51
  • $\begingroup$ @AQ I have revised the answer. $\endgroup$ Commented Mar 6, 2021 at 9:02
  • $\begingroup$ @AQ there is a bracket missing in NestList[(r # ^2 - #) &, .1, 300] $\endgroup$
    – Andreas
    Commented Mar 6, 2021 at 12:44
  • $\begingroup$ OP's question is about a differential equation, not a difference equation, but maybe that's what they meant? $\endgroup$
    – Chris K
    Commented Mar 6, 2021 at 13:41

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