In this lecture, we're going to take a look at pitchfork bifurcations. In this kind of bifurcation, changing a parameter of the problem leads to the formation or destruction of fixed points. We will begin with the equation $\dot{x} = rx-x^3$.
1;
set(0, "defaultlinelinewidth", 4);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
graphics_toolkit qt;
error: graphics_toolkit: qt toolkit is not available error: called from graphics_toolkit at line 81 column 5
r_a = linspace(-3, 3,33);
function y = f(x, r)
y = r*x- x.^3;
end
function dy = dfdx(x, r)
dy = r-3*x.^2;
end
for i=1:length(r_a)
r = r_a(i);
[sol, fval, info]= fsolve(@(x) f(x, r), [-2 0 2]);
if info == 1 % Solution has converged
for j = 1:length(sol)
root = sol(j);
slope_at_root = dfdx(root, r);
if slope_at_root >= 0
plot(r, root, 'bx');
else
plot(r, root, 'ro');
hold on;
end
end
end
end
xlim([min(r_a) max(r_a)]);
line ([min(r_a) max(r_a)], [0 0], "linestyle", "-", "color", "m");
line ([0 0], [min(r_a) max(r_a)],"linestyle", "-", "color", "m");
xlabel("r");
ylabel("x*");
title("Supercritical pitchfork bifurcation");
hold off;
warning: matrix singular to machine precision, rcond = 7.40149e-17 warning: called from fsolve>__dogleg__ at line 532 column 5 fsolve at line 351 column 11 warning: matrix singular to machine precision, rcond = 7.40149e-17 warning: called from fsolve>__dogleg__ at line 532 column 5 fsolve at line 351 column 11 warning: matrix singular to machine precision, rcond = 9.36751e-17 warning: called from fsolve>__dogleg__ at line 532 column 5 fsolve at line 351 column 11
set(0, "defaultlinelinewidth", 2);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
end
if (recalc || init)
r = -2 + 4*get (h.slider1, "value");
set (h.label1, "string", sprintf ("r: %.1f", r));
x = linspace(-2,2);
xd = r*x - x.^3;
h.plot = plot(x, xd, x, 0.*x, '-k');
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
Inline plot failed, consider trying another graphics toolkit
error: __gnuplot_draw_figure__: unknown object class, uicontrol
error: called from
_make_figures>safe_print at line 125 column 7
_make_figures at line 49 column 13
set(0, "defaultlinelinewidth", 2);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
end
if (recalc || init)
r = -2 + 4*get (h.slider1, "value");
set (h.label1, "string", sprintf ("r: %.1f", r));
x = linspace(-2,2);
xd = -x + r*tanh(x);
h.plot = plot(x, xd, x, 0.*x, '-k');
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
Inline plot failed, consider trying another graphics toolkit
error: __gnuplot_draw_figure__: unknown object class, uicontrol
error: called from
_make_figures>safe_print at line 125 column 7
_make_figures at line 49 column 13
In the snippet that follows, we aim at looking at the bifurcation diagram $\dot{x} = -x + r\tanh(x)$
r_a = linspace(-2, 2,33);
function y=f(x, r)
y=-x + r*tanh(x);
end
function dy=dfdx(x, r)
dy= -1 + r*1/(cosh(x)).^2;
end
for r = r_a
[sol, fval, info] = fsolve(@(x) f(x,r), [-2,0, 2]);
if info == 1 # Solution has converged
for i=1:length(sol)
root = sol(i);
slope_at_root = dfdx(root, r);
if slope_at_root > 0
plot(r, root, 'bx');
else
plot(r, root, 'ro');
end
hold on;
end
end
end
xlim([min(r_a), max(r_a)]);
line ([min(r_a) max(r_a)], [0 0], "linestyle", "-", "color", "m");
line ([0 0], [min(r_a) max(r_a)],"linestyle", "-", "color", "m");
xlabel("r");
ylabel("x*");
title("Supercritical pitchfork bifurcation");
hold off;
set(0, "defaultlinelinewidth", 2);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
end
if (recalc || init)
r = -2 + 4*get (h.slider1, "value");
set (h.label1, "string", sprintf ("r: %.1f", r));
x = linspace(-2,2);
xd = r*tanh(x);
h.plot = plot(x, xd, x, x, x, 0.*x, '-k');
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
Inline plot failed, consider trying another graphics toolkit
error: __gnuplot_draw_figure__: unknown object class, uicontrol
error: called from
_make_figures>safe_print at line 125 column 7
_make_figures at line 49 column 13
set(0, "defaultlinelinewidth", 2);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
end
if (recalc || init)
r = -2 + 4*get (h.slider1, "value");
set (h.label1, "string", sprintf ("r: %.1f", r));
x = linspace(-2,2);
xd = r*x + x.^3;
h.plot = plot(x, xd,x, 0.*x, '-k');
h.title = title("\dot{x} = rx + x^3");
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
Inline plot failed, consider trying another graphics toolkit
error: __gnuplot_draw_figure__: unknown object class, uicontrol
error: called from
_make_figures>safe_print at line 125 column 7
_make_figures at line 49 column 13
In the snippet that follows, we aim at looking at the bifurcation diagram $\dot{x} = -x + r\tanh(x)$
set(0, "defaultlinelinewidth", 2);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
end
if (recalc || init)
r = -2 + 4*get (h.slider1, "value");
set (h.label1, "string", sprintf ("r: %.1f", r));
x = linspace(-2,2);
xd = r*x + x.^3 - x.^5;
h.plot = plot(x, xd,x, 0.*x, '-k');
h.title = title("\\dot{x} = rx + x^3 - x^5");
h.ylim = ylim([-0.25, 0.25]);
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
error: value on right hand side of assignment is undefined error: called from update_plot at line 21 column 14
Inline plot failed, consider trying another graphics toolkit
error: __gnuplot_draw_figure__: unknown object class, uicontrol
error: called from
_make_figures>safe_print at line 125 column 7
_make_figures at line 49 column 13
#will take a while to compute
1;
function y=f(x, r)
y=r*x + x.^3 - x.^5;
end
function dy= dfdx(x, r)
dy= r + 3*x.^2 - 5*x.^4;
end
x = linspace(-2, 2,50); r_a = linspace(-0.5, 1,100);
xg = linspace(-2,2,20);
for r=r_a
[sol, fval, info] = fsolve(@(x) f(x,r), xg);
if info == 1 # Solution has convered
for i=1:length(sol)
root = sol(i);
slope_at_root = dfdx(root, r);
if slope_at_root > 0
plot(r, root, 'bx')
else
plot(r, root, 'ro')
end
hold on;
end
end
end
xlim([min(r_a), max(r_a)]);
line ([min(r_a) max(r_a)], [0 0], "linestyle", "-", "color", "m");
line ([0 0], [min(r_a) max(r_a)],"linestyle", "-", "color", "m");
xlabel("r");
ylabel("x*");
title("Subcritical pitchfork bifurcation");
hold off;
clear;
clc; close all;
h.ax = axes ("position", [0.05 0.4 0.5 0.5]); #reduce plot windows size to accomodate sliders
function y = f(x, t, r)
y = r*x + x.^3 - x.^5;
end
function update_plot (obj, init = false)
## gcbo holds the handle of the control
h = guidata (obj);
replot = false;
recalc = false;
switch (gcbo) # If we make any change then we replot
case {h.print_pushbutton}
fn = uiputfile ("*.png");
print (fn);
case {h.slider1}
recalc = true;
case {h.slider2}
recalc = true;
case {h.slider3}
recalc = true;
end
if (recalc || init)
x0 = -0.1+ 0.6*get (h.slider1, "value");
r = -0.5 + 0.9*get (h.slider2, "value");
t_end = 10 + 40*get (h.slider3, "value");
set (h.label1, "string", sprintf ("x0: %.1f", x0));
set (h.label2, "string", sprintf ("r: %.1f", r));
set (h.label3, "string", sprintf ("t_end: %.1f", t_end));
t=linspace(0,t_end,100)';
xd = @(x,t) f(x, t, r);
sol = lsode(xd, x0, t);
plot(t, sol, "-k");
xlabel("t"); ylabel("x");
ylim([-1.2, 1.2]);
guidata (obj, h);
else
set (h.plot, "ydata", y);
end
end
# specify the GUI plot properties like sliders and label formatting
## print figure
h.print_pushbutton = uicontrol ("style", "pushbutton",
"units", "normalized",
"string", "print plot\n(pushbutton)",
"callback", @update_plot,
"position", [0.6 0.45 0.35 0.09]);
## guess
h.label1 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.05 0.25 0.35 0.08]);
h.slider1 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.05 0.20 0.35 0.06]);
h.label2 = uicontrol ("style", "text",
"units", "normalized",
"string", "Iteration:",
"horizontalalignment", "left",
"position", [0.05 0.15 0.35 0.08]);
h.slider2 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.5,
"position", [0.05 0.10 0.35 0.06]);
h.label3 = uicontrol ("style", "text",
"units", "normalized",
"string", "Guess:",
"horizontalalignment", "left",
"position", [0.6 0.25 0.35 0.08]);
h.slider3 = uicontrol ("style", "slider",
"units", "normalized",
"string", "slider",
"callback", @update_plot,
"value", 0.1,
"position", [0.6 0.20 0.35 0.06]);
set (gcf, "color", get(0, "defaultuicontrolbackgroundcolor"))
guidata (gcf, h)
update_plot (gcf, true);
Inline plot failed, consider trying another graphics toolkit
error: __gnuplot_draw_figure__: unknown object class, uicontrol
error: called from
_make_figures>safe_print at line 125 column 7
_make_figures at line 49 column 13