% The first example of specific equations undergoing the catastrophe 
% (Blue Sky Catastrophe) was given by N. Gavrilov and A. Shilnikov 
% [Gavrilov and Shilnikov, 2000; L. Shilnikov et al, 2001]
%
%   dx/dt = x(2+mu-beta((x^2)+(y^2)))+(z^2)+(y^2)+2*y
%   dy/dt = -(z^3)-(1+y)((z^2)+(y^2)+2y)-4x+ mu y
%   dz/dt = (1+y)(z^2)+(x^2)-eta.
%
% Early development of the blue sky catastrophe in this system begins
% with a homoclinic connection to an equilibrium state with the 
% characteristic exponents (0,-+i.omega); this is indeed a cod-2 bifurcation named 
% after Gavrilov-Guckenheimer or aka the homoclinic Fold-Hopf.
% The blue sky catastrophe has turned out to be a typical phenomenon 
% in slow-fast systems [L. Shilnikov et al, 2001; A. Shilnikov et al,2005]. 



global mu beta eta
mu=0.456; 
beta=10;
eta=0.0357;    
x0=[0 0 0];
[t, X] = ode45(@BSCgeneric, [0 1000], x0);  
% For t, an interesting parameter setting 
% can be used [0 10000] rather than [0 100]
%
m1=min(X(:,1));m2=min(X(:,2));m3=min(X(:,3));
M1=max(X(:,1));M2=max(X(:,2));M3=max(X(:,3));
plot3(X(:,3),X(:,2),X(:,1));
xlabel('x');
ylabel('y');   
zlabel('z');
axis([m3 M3 m2 M2 m1 M1])
view([0, 0, 1]);
grid
box;

% "Complex and Chaotic Nonlinear Dynamics. 
% Advances in Economics and Finance, 
% Mathematics and Statistics" 
% T.Vialar, Springer 2009
% Copyright(c).