Gershgorin's Circle: how can I find the intersection of the union of circles?

60 views (last 30 days)
Good Morning, I'm trying to do a program that calculates the Gerschgorin's circles (for rows and for columns).
The following program creates the Gerschgorin's Circle for matrix A and plot them (in the first figure) and for the matrix A^T (in the second figure).
What I want to do is to find the union of the circles of the matrix A, find the union of the circles of the matrix A^T and plot the intesection between the two unions. I tried with the polyshape and the polyout but it seems not to work.
The program it's the following:
% gerschgorin.m
function gerschgorin(A)
if size(A,1) ~= size(A,2)
error('La matrice deve essere quadrata.'); %The matrix must be square
return;
end
%FIGURE 1:I calculate and represent the circles associated with matrix A;
figure;
for i=1:size(A,1)
% The circle's center is (h,k) where h is the real part of A(i,i) and k is the imaginary part of A(i,i);
h=real(A(i,i)); k=imag(A(i,i));
% I find the radius of the circle;
r=0;
for j=1:size(A,1)
if i ~= j
r=r+(norm(A(i,j)));
end
end
t=0:0.01:2*pi;
plot( r*cos(t)+h, r*sin(t)+k ,'-'); %I use the polar coordinates
hold on
c=plot( h, k,'bo');
title('Circles of the matrix A')
end
% Now we plot the actual eigenvalues of the matrix;
ev=eig(A);
for i=1:size(ev)
rev=plot(real(ev(i)),imag(ev(i)),'ro');
end
xline(0); yline(0);
axis equal;
legend([c rev],'Centri','Autovalori')
grid on;
xlabel('Parte Reale'); ylabel('Parte Immaginaria')
%FIGURE 2:I calculate and represent the circles associated with matrix A^T;
figure;
for i=1:size(A,1)
h=real(A(i,i)); k=imag(A(i,i));
r=0;
for j=1:size(A,1)
if i ~= j
r=r+(norm(A(j,i)));
end
end
t=0:0.01:2*pi;
plot( r*cos(t)+h, r*sin(t)+k ,'-'); hold on;
c=plot( h, k,'bo');
title('Cerchi associati alla matrice \itA^{T}')
end
%Eigenvalues
ev=eig(A);
for i=1:size(ev)
rev=plot(real(ev(i)),imag(ev(i)),'ro');
end
xline(0); yline(0);
axis equal;
legend([c rev],'Centri','Autovalori')
grid on;
xlabel('Parte Reale'); ylabel('Parte Immaginaria')
% FIGURE 3: Intersection
figure;
for i =1:size (A,1)
h = real (A(i,i));k=imag(A(i,i)) ;
r1 =0; r2 =0;
for j =1: size(A,1)
if i ~=j
r1=r1+(norm(A(i,j)));
r2=r2+(norm(A(j,i)));
x1=r1*cos(t)+h;
y1=r1*sin(t)+k,'-';
x2=r2*cos(t)+h;
y2=r2*sin(t)+k,'-';
pgon1=polyshape(x1,y1);
pgon2=polyshape(x2,y2);
polyout1=union(pgon1);
polyout2=union(pgon2);
end
end
plot(intersect(polyout1,polyout2),'EdgeColor','red')
hold on;
c = plot (h,k,'bo');
%title ( ' Intersezione dei due insiemi di cerchi ')
end
%Eigenvalues
ev=eig(A);
for i=1:size(ev)
rev=plot(real(ev(i)),imag(ev(i)),'ro');
end
xline(0); yline(0);
axis equal;
grid on;
xlabel('Parte Reale'); ylabel('Parte Immaginaria')
legend([c rev],'Centri','Autovalori')
end
THANK YOU for everyone who's going to answer me!

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 11 Jun 2023
warning off;
% gerschgorin.m
A=magic(5);
gerschgorin(A)
function gerschgorin(A)
if size(A,1) ~= size(A,2)
error('La matrice deve essere quadrata.'); % The matrix must be square.
return;
end
% FIGURE 1: Calculate and represent the circles associated with matrix A.
figure;
for i = 1:size(A,1)
% The circle's center is (h, k) where h is the real part of A(i,i) and k is the imaginary part of A(i,i).
h = real(A(i,i));
k = imag(A(i,i));
% Find the radius of the circle.
r = 0;
for j = 1:size(A,1)
if i ~= j
r = r + abs(A(i,j));
end
end
t = 0:0.01:2*pi;
plot(r*cos(t)+h, r*sin(t)+k, '-'); % Use polar coordinates.
hold on;
c = plot(h, k, 'bo');
end
% Plot the actual eigenvalues of the matrix.
ev = eig(A);
rev = plot(real(ev), imag(ev), 'ro');
xline(0);
yline(0);
axis equal;
legend([c rev], 'Centri', 'Autovalori');
grid on;
xlabel('Parte Reale');
ylabel('Parte Immaginaria');
title('Circles of matrix A');
% FIGURE 2: Calculate and represent the circles associated with matrix A^T.
figure;
for i = 1:size(A,1)
h = real(A(i,i));
k = imag(A(i,i));
r = 0;
for j = 1:size(A,1)
if i ~= j
r = r + abs(A(j,i));
end
end
t = 0:0.01:2*pi;
plot(r*cos(t)+h, r*sin(t)+k, '-');
hold on;
c = plot(h, k, 'bo');
end
% Plot the actual eigenvalues of the matrix.
ev = eig(A);
rev = plot(real(ev), imag(ev), 'ro');
xline(0);
yline(0);
axis equal;
legend([c rev], 'Centri', 'Autovalori');
grid on;
xlabel('Parte Reale');
ylabel('Parte Immaginaria');
title('Circles of matrix A^T');
% FIGURE 3: Intersection of the union of circles for A and A^T.
figure;
for i = 1:size(A,1)
h = real(A(i,i));
k = imag(A(i,i));
r1 = 0;
r2 = 0;
x = [];
y = [];
for j = 1:size(A,1)
if i ~= j
r1 = r1 + abs(A(i,j));
r2 = r2 + abs(A(j,i));
x1 = r1*cos(t) + h;
y1 = r1*sin(t) + k;
x2 = r2*cos(t) + h;
y2 = r2*sin(t) + k;
x = [x, x1];
y = [y, y1];
end
end
polyout1 = polyshape(x, y);
polyout2 = polyshape(x2, y2);
intersection = intersect(polyout1, polyout2);
plot(intersection, 'EdgeColor', 'red');
hold on;
c = plot(h, k, 'bo');
end
% Plot the actual eigenvalues of the matrix.
ev = eig(A);
rev = plot(real(ev), imag(ev), 'ro');
xline(0);
yline(0);
axis equal;
grid on;
xlabel('Parte Reale');
ylabel('Parte Immaginaria');
title('Intersection of the union of circles for A and A^T');
legend([c rev], 'Centri', 'Autovalori');
end
  4 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 12 Jun 2023
warning off;
% gerschgorin.m
A=[-2 0 -6
2 -2 0
0 2 -2];
gerschgorin(A)
function gerschgorin(A)
if size(A,1) ~= size(A,2)
error('La matrice deve essere quadrata.'); % The matrix must be square.
return;
end
% FIGURE 1: Calculate and represent the circles associated with matrix A.
figure;
for i = 1:size(A,1)
% The circle's center is (h, k) where h is the real part of A(i,i) and k is the imaginary part of A(i,i).
h = real(A(i,i));
k = imag(A(i,i));
% Find the radius of the circle.
r = 0;
for j = 1:size(A,1)
if i ~= j
r = r + abs(A(i,j));
end
end
t = 0:0.01:2*pi;
plot(r*cos(t)+h, r*sin(t)+k, '-'); % Use polar coordinates.
hold on;
c = plot(h, k, 'bo');
end
% Plot the actual eigenvalues of the matrix.
ev = eig(A);
rev = plot(real(ev), imag(ev), 'ro');
xline(0);
yline(0);
axis equal;
legend([c rev], 'Centri', 'Autovalori');
grid on;
xlabel('Parte Reale');
ylabel('Parte Immaginaria');
title('Circles of matrix A');
% FIGURE 2: Calculate and represent the circles associated with matrix A^T.
figure;
for i = 1:size(A,1)
h = real(A(i,i));
k = imag(A(i,i));
r = 0;
for j = 1:size(A,1)
if i ~= j
r = r + abs(A(j,i));
end
end
t = 0:0.01:2*pi;
plot(r*cos(t)+h, r*sin(t)+k, '-');
hold on;
c = plot(h, k, 'bo');
end
% Plot the actual eigenvalues of the matrix.
ev = eig(A);
rev = plot(real(ev), imag(ev), 'ro');
xline(0);
yline(0);
axis equal;
legend([c rev], 'Centri', 'Autovalori');
grid on;
xlabel('Parte Reale');
ylabel('Parte Immaginaria');
title('Circles of matrix A^T');
% FIGURE 3: Intersection of the union of circles for A and A^T.
figure;
for i = 1:size(A,1)
h = real(A(i,i));
k = imag(A(i,i));
r1 = 0;
r2 = 0;
x = [];
y = [];
for j = 1:size(A,1)
if i ~= j
r1 = r1 + abs(A(i,j));
r2 = r2 + abs(A(j,i));
x1 = r1*cos(t) + h;
y1 = r1*sin(t) + k;
x2 = r2*cos(t) + h;
y2 = r2*sin(t) + k;
x = [x, x1];
y = [y, y1];
end
end
polyout1 = polyshape(x, y);
polyout2 = polyshape(x2, y2);
intersection = intersect(polyout1, polyout2);
plot(intersection, 'EdgeColor', 'red');
hold on;
c = plot(h, k, 'bo');
end
% Plot the actual eigenvalues of the matrix.
ev = eig(A);
rev = plot(real(ev), imag(ev), 'ro');
xline(0);
yline(0);
axis equal;
grid on;
xlabel('Parte Reale');
ylabel('Parte Immaginaria');
title('Intersection of the union of circles for A and A^T');
legend([c rev], 'Centri', 'Autovalori');
end
Federica Mina
Federica Mina on 12 Jun 2023
@KALYAN ACHARJYA Yes exactly what I meant. My purpose is to plot the intersection between the union of the circles of matrix A and the union of circles of matrix A^T. Then the intersection must to include all the eigenvalues of the matrix A. So in this case two of the eigenvalues are outside of the circle. Should I change somenthing else in the program? Thank you for your answer by the way.

Sign in to comment.

More Answers (0)

Categories

Find more on Formatting and Annotation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!