% demonstrate the Bauer-Fike Theorem
clear all; clc;

n = 6;

% define a matrix A
A = randn(n,n) + i*rand(n,n);

% define a perturbation delta_A
delta_A = 0.025*(randn(n,n) + i*rand(n,n));

% compute eigenvalues, eigenvectors
[V,D] = eig(A);
[V_tilde,D_tilde] = eig(A+delta_A);

% compute norm of perturbation radius
radius = cond(V)*norm(delta_A);

% plot the unperturbed eigenvalues
plot(real(diag(D)),imag(diag(D)),'kx','markersize',12,'linewidth',2)
hold on
% plot the perturbed eigenvalues
plot(real(diag(D_tilde)),imag(diag(D_tilde)),'r+','markersize',12,'linewidth',2)
axis equal
xlabel('real$(\lambda)$','interpreter','latex','fontsize',18)
ylabel('imag$(\lambda)$','interpreter','latex','fontsize',18)

% plot the disks
for i=1:n
    draw_circle([real(D(i,i)),imag(D(i,i))],radius)
end
hold off