Gershgorin's Circle: how can I find the intersection of the union of circles?
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





