Gershgorin's Circle: how can I find the intersection of the union of circles?
56 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
KALYAN ACHARJYA
2023 年 6 月 11 日
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 件のコメント
KALYAN ACHARJYA
2023 年 6 月 12 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Formatting and Annotation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!