%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         7.gyakorlat         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Nemlin. din. rsz-ek alapjai %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        2014.11.12/13        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          Bifurkációk        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Schnakenberg egyenlet, Hopf-bifurkáció
% oscillation, glikolízis, 
% trimolecular, autokatalízis: maga képzõdését katalizál
% 2x+y->3x
% x<->a=1/8
% mu->y
% dxdt=x(t)^2*y(t)-x(t)+a
% dydt=-x(t)^2*y(t)+mu

figure;
    
t0=[0 400];
xkoord=[0.1, 0.1, 1, 2, 0.1]; %kezdeti pontok, ahonnana  a trajektóriákat indítom
ykoord=[0.1, 2, 1, 2, 4];

% ide jön a megoldás:


%{
    %vektormezõs ábra:
    points=0:0.2:6;
    [X, Y] = meshgrid(points, points);
    dx=1/8-X+X.^2.*Y; 
    dy=mu-X.^2.*Y;
    dx=dx./ sqrt(dx.^2+dy.^2); %vektormezõ lenormálva
    dy=dy./sqrt(dx.^2+dy.^2);
    quiver(X,Y,dx, dy, 'k');
    hold on;
   %}
    
   subplot(1,2,1);
    plot(xmg, ymg); %kirajzol pontokhoz tartozó trajektóriákat
    title(['Schnakenberg modell: mu=', num2str(mu), ' dxdt=1/8-x+x^2*y; dydt=mu-x^2*y']);
    xlabel('x');
    xlim([-0.1 6]);
    ylabel('y');
    ylim([-0.1 6]);
    hold off;
    
    %
    subplot(1,2,2);
    pont=4;
    plot(mgt(:,pont), xmg(:,pont), 'b', mgt(:,pont), ymg(:,pont), 'r'); %kirajzolja adott kezdeti x,y változásait az idõben
    xlabel('t');
    ylabel('x,y');
    legend('x','y');
    title(['kezdõpont: [', num2str([xkoord(pont), ykoord(pont)]) ,']']);
    %}
    waitforbuttonpress;
    %pause(0.1);
end
