I need to plot the bifurcation diagram for the function given below.
g[x_, r_] := 6 x^2 + r x^4 + x^6
Plot[g[x, -4.9], {x, -2, 2}]
Bifurcation
Code for bifurcation is burrowed from Coloring Bifurcation Diagram question:
CClear[NotComplexQ];
NotComplexQ[c_Complex] := False;
NotComplexQ[c_] := True
CartProd[l_] := Outer[List, l[[1]], l[[2]]]
ArreglaLista[l_] := Select[Map[(x /. #) &, Flatten[l]], NotComplexQ]
Points = Flatten[
Map[CartProd,
Table[{{r}, ArreglaLista[NSolve[g2[x, r] == 0, x]]}, {r, -20, 10,
0.01}]], 2];
ListPlot[Points]
Colouring
I've also borrowed the code from the answer by @Kuba to the above-mentioned question, however, it does not work for my problem. How to modify it to get the desired result?
unstable = Select[Points, First@# >= 0 && Last@# == 0 &];
stable =
SortBy[#,
First] & /@ (Append[#, {0, 0}] & /@ (GatherBy[
Complement[Points, unstable], Sign@Last@# &]));
ListPlot[stable~Join~{unstable},
PlotStyle -> {Directive[Red, Dashing[0.01]],
Directive[ Blue, Dashing[0.01]],
Directive[ Red, Dashing[0.008]],
Directive[ Blue, Dashing[0.1]]}]
I want the stable line for r>0 to be solid blue, the stable lines for r<0 to be in dashed blue line and the unstable lines to be red dashed.
Is there any general method to do it?
Please help me out. Thank you.