In control theory, bifurcation is generally described as a sudden topological change
in behavior in a system. More specifically,
the term refers to a change in a system behavior when a parameter or set of parameters are varied.
The code snippet below is a MATLAB script that can be run to form the subsequent plots.
It begins by initializing differential equations and forming state space (ss
)
equations Z1
and Z2
.
With these, a meshgrid and vector field can be computed and plotted on.
We'd also like to overlay contours of the ode45 numerical solution to our state space
and so we loop over a range of initial conditions (x_range
)
and contour values (Z_sol
) to obtain
a plot that resembles 1 frame of the GIFs shown below.
In order to form the GIF, many of these individual frames needed
to be created with the parameter a
being varied across a range of -3:3 at 0.1 increments (a_range
).
A simple for loop will allows us to iterate over our desired range,
saving the files as .jpg images as we go. This then allows us to upload all the .jpg
images into a GIF creating tool online at gifmaker.me forming
a nice looping GIF of our images.
Finer increments of iteration across our range give better smoothness to the GIF,
although chewing up large amount of memory.
Essentially, bifurcation is the topological change that is visible when a
is varied
across a_range
. In linear systems this is not present, since linear change input
maps to linear change in output. Bifurcation is an interesting behavior that arises in non-linear systems
since its can give rise to system altering toplogies like limit cycles and
stable/unstable equilibrium.
Fig. 1 was formed using exactly this source code. Fig. 2 is a
slight deviation in ss
. The a
value
located in the second equation is replaced with a 1. This gives rise
to a asymmetrical spreading of the trajectories.
% Script plotting phase portraits of non-linear bifurcations [Fig1]
% init system and states
number = 1;
for a_range = -3:0.1:3
g = 9.81;
L = 1;
a = a_range;
b = 0.1;
ss = @(t,Z) [Z(2)+Z(1)*(a-Z(1)^2-Z(2)^2); -Z(1)+Z(2)*(a-Z(1)^2-Z(2)^2)];
Z1 = linspace(-pi,pi,25);
Z2 = linspace(-pi,pi,25);
% Generate Meshgrid for numerically solving
[x,y] = meshgrid(Z1,Z2);
size(x)
size(y)
% Establish U and V vectors
u = zeros(size(x));
v = zeros(size(y));
% Init Loop over Vector field to compute Derivatives
t = 0;
for i = 1:numel(x)
Theta_d = ss(t,[x(i); y(i)]);
u(i) = Theta_d(1);
v(i) = Theta_d(2);
Mag = sqrt(u(i)^2+v(i)^2);
u(i) = u(i)/Mag;
v(i) = v(i)/Mag;
end
%Plot our vector field
figure
quiver(x,y,u,v,'r'); figure(gcf)
xlabel('X')
ylabel('Y')
axis tight equal;
hold on
for x_range = [-1,0,1]
for Z_sol = -10:1:10
[ts,ys] = ode45(ss,[0,10],[x_range;Z_sol]);
plot(ys(:,1),ys(:,2),'b');
%plot(-ys(:,1),ys(:,2),'b')
%plot(ys(1,1),ys(1,2),'bo') %start of contour
%plot(ys(end,1),ys(end,2),'ks') %end of contour
end
end
axis([-2 2 -2 2])
grid on
s1 = 'figure_';
s2 = num2str(number);
s3 = '.jpg';
filo = strcat(s1,s2,s3);
number = number+1;
doc saveas
saveas(gcf,filo);
end