- N = 256;: This line sets the value of N to 256. This determines the number of points we want to create on the circle.
- t = (0:N)*2*pi/N;: This line creates the vector t by performing the following steps:
- (0:N) creates a row vector from 0 to N, where each element represents the index of a point on the circle.
- 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.
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!
% 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.
if size(A,1) ~= size(A,2)
error('Matrix should be square');
% For each row, we say:
% 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) :
% 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
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
plot( r*cos(t)+h, r*sin(t)+k ,'-');
% We also plot the center of the circle for better undesrtanding:
plot( h, k,'+');
% For the circles to be better graphed, we would like to have equal axis:
% Now we plot the actual eigenvalues of the matrix:
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:
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, '-');
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,