% dependence of eigenvalues on a parameter "a"

clc;clear all;

% parameter "a" varying between 0 and 5
a = 0:.1:5;

% creating a variable to store eigenvalues for each value of the parameter "a"
lambda = zeros(2,length(a));

% loop that constructs "A" for each parameter value of "a", computes eigenvalues of "A" and stores them in "lambda"
for kk=1:length(a)
 A = [-1,1;0,cos(a(kk))]; % create the corresponding matrix
 eigenvalues = eig(A); % compute the eigenvalues
 lambda(:,kk) = eigenvalues; % store the eigenvalues
end

% displaying the matrix structure
display('A =')
display(' -1  1')
display('  0  cos(a)')

%%% plotting the dependence of eigenvalues on parameter

figure;

% plot for first EV
subplot(1,2,1)
plot(a,lambda(1,:),'r');
xlabel('a');
legend('\lambda_1')
title('Depencence for first eigenvalue')

% plot for second EV
subplot(1,2,2)
plot(a,lambda(2,:),'b');
xlabel('a');
legend('\lambda_2')
title('Depencence for second eigenvalue')