Goodmorning.Can some explain to me some steps of this program (downloaded from "Gershgorin Discs Plot Version by Mario Berge" I have highlighted them.

26 次查看(过去 30 天)
Goodmorning.Can some explain to me some steps of this program (downloaded from "Gershgorin Discs Plot Version by Mario Berge" I have highlighted them. And I want to ask also how can I first plot just the "row" circles and then the "column" circles.
Thanks very much for your answers!
% gerschdisc.m
% This function plots the Gershgorin Discs for the matrix A passed as an argument.
% It will also plot the centers of such discs, and the actual eigenvalues
% of the matrix.
function gershdisc(A)
if size(A,1) ~= size(A,2)
error('Matrix should be square');
% For each row, we say:
for i=1:size(A,1)
% The circle has center in (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));
% Now we try to compute the radius of the circle, which is nothing more
% than the sum of norm of the elements in the row where i != j
for j=1:size(A,1)
if i ~= j
% We try to make a vector of points for the circle:
% Now we're able to map each of the elements of this vector into a
% circle:
plot( r*cos(t)+h, r*sin(t)+k ,'-');
% We also plot the center of the circle for better undesrtanding:
hold on;
plot( h, k,'+');
% For the circles to be better graphed, we would like to have equal axis:
axis equal;
% Now we plot the actual eigenvalues of the matrix:
for i=1:size(ev)
hold off;
legend(rev,'Actual Eigenvalues');

回答(1 个)

Dinesh 2023-6-9
Hi Federica!
In the given code the highlighted part code is used create a vector 't' of 'N+1' equally spaced points around the circumference of a circle. Here's what each line does:
  1. N = 256;: This line sets the value of N to 256. This determines the number of points we want to create on the circle.
  2. t = (0:N)*2*pi/N;: This line creates the vector t by performing the following steps:
  3. (0:N) creates a row vector from 0 to N, where each element represents the index of a point on the circle.
  4. 2*pi/N scales the vector by multiplying each element by 2*pi/N. This step ensures that the points span the full circumference of the circle, from 0 to 2*pi.
So, the resulting vector 't' contains 'N+1' equally spaced points around the circle, covering the range from 0 to 2*pi. These points will be later used to map each point on the circumference of the circle when plotting the Gershgorin Discs.
To plot the row circles and column circles seperately you can introduce two separate loops: one for rows and one for columns.
a sample code would look like this
% Plot row circles
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(i,j));
N = 256;
t = (0:N)*2*pi/N;
plot(r*cos(t) + h, r*sin(t) + k, '-');
hold on;
plot(h, k, '+');
Similarly for the column circles Change the
for i = 1:size(A,2)
for j = i:size(A,2)
Hope this helps,
Thank you!


Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by