# Bifurcation Diagram plotting [closed]

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.

• Perhaps this would be a useful example. Commented Mar 7, 2021 at 5:07
• “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. Commented Mar 7, 2021 at 6:27
• @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.
– A Q
Commented Mar 7, 2021 at 6:34

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}]


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}}]
]


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

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