%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         3. practice         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Nonlinear dynamics systems  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         2019.10.01.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Trace-Determinant diagram  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;

% plot trajectories from given points,
% change the matrix, the phase portrait also changes (eigenvalue, det, trace also shown)
x = -4:1:4;
y = -4:1:4;
[X Y] = meshgrid(x,y);

K = 500;
fix = zeros(K,length(x)*length(y)); % initial points for ode45
fiy = zeros(K,length(x)*length(y));

figure;
% plot trace-determinant curve
subplot(1,2,2);
tr=(-8:0.1:8);

%1. plot the tr=0; det=0; tr=tr^2/4 lines
plot();

xlabel('trace');
ylabel('det');
hold on;

    %2. implement the system for different -3<a<3 parameters:
    % ddx-2a*dx+(4-a^2)*x=0
    % Jacobi matrix:
    A = [] % matrix form of the equations
   
se=; %3. eigenvalues
% solve the diffequ for each system:
 n=1;
for i = 1:length(x)
    for j = 1:length(y)
        [t,fi] = ode45(@(t,y) A*y, linspace(0,5,K), [x(i) y(j)]); %calculate ode45 in given points
        fix(:,n) = fi(:,1); % store the results in the given rpws of 'fix' and 'fiy'
        fiy(:,n) = fi(:,2);
        n = n+1;
    end
end

%plot trajectories from given points:
subplot(1,2,1);
plot(fix,fiy);
hold on;
plot(X,Y,'x');
xlim([2*min(x) 2*max(x)]);
ylim([2*min(y) 2*max(y)]);
title(['eigenvalues: ', num2str(se(1)), ', ', num2str(se(2))]);
xlabel('x');
ylabel('y');
hold off

%4. trace det plot:
subplot(1,2,2);
trace_mx=;
det_mx=;
plot();
title(['trace(A): ', num2str(trace_mx), ', det(A):', num2str(det_mx)]);

waitforbuttonpress;
%pause(0.1)
