Gerschgorin circles: intersection of union of circles
    10 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Good Morning, 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). In the third figure the program should find the INTERSECTION of the union of the circles of the matrix A and the union of circles or matrix A^T.  In symbol

where
 and Hi it's the same but for columns.
 and Hi it's the same but for columns.For example for the matrix
    -2     0    -6
     2    -2     0
     0     2    -2
The program doesn't work because in the third figure it should plot a circles with center -2 and radius 6. 
The program it's the following:
function gerschgorin(A)
if size(A,1) ~= size(A,2) %Il numero delle righe deve essere uguale al numero delle colonne;
    error('La matrice deve essere quadrata.');
    return;
end
%FIGURA 1: Calcolo e rappresento i cerchi associati alla matrice A;
figure; 
for i=1:size(A,1) 
    % Il cerchio ha centro in (h,k) dove h equivale alla parte reale di A(i,i)
    %(i-esimo elemento della diagonale di A) e k che equivale alla parte immaginaria di A(i,i);
    h=real(A(i,i)); k=imag(A(i,i)); 
    % Calcolo il raggio del cerchio;
    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; %I valori di t variano da 0 a 2pigreco con passo 0.01;
    plot( r*cos(t)+h, r*sin(t)+k ,'-'); %Rappresento i cerchi con le coordinate polari;
    hold on
    c=plot( h, k,'bo'); %Rappresento i centri dei cerchi con dei pallini blu;
    title('Cerchi associati alla matrice A')
end
%Autovalori: calcolo e rapresento gli autovalori con pallini rossi;
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')
%FIGURA 2:Calcolo e rappresento i cerchi associati alla matrice A trasposta;
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
%Autovalori
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')
% FIGURA 3: Rappresento l' intersezione tra l'unione dei cerchi associati alla matrice A e l'unione 
% dei cerchi associati alla matrice A ^ T (l'intersezione è data dalle aree con il bordo
% rosso)
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');
        title ("INtersezione dei due insiemi di cerchi");
    end
%Autovalori (Calcolo e rappresentazione con pallini rossi)
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 your anwers.
0 commentaires
Réponses (1)
  Adeline
      
 le 25 Août 2023
        I understand you are trying to execute a program to create the Gerschgorin's Circle for the example matrix A.  
The mentioned code has three sections where section-1 generates three circles plotted in figure 1 with their centers at -2 and radius as 6, 2 and 2, respectively. Similarly, section-2 plots three circles with their centers at -2 and radius as 2, 2 and 6, respectively.  
In the third section, the objective is to unite the three circles from section-1 to form one polyshape. Similarly, the three circles in section-2 should form another polyshape. The intersection of these polyshapes would result in a single circle with center 2 and radius 6. 
However, the mentioned code intersects the first circle generated in section-1 with the first circle generated in section-2. It repeats these steps for the next two circles resulting in three circles with centre at -2 and radius as 2.  
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
