how do i include the one point in the complex plane in my legend
2 views (last 30 days)
Show older comments
Hi all
im plotting gershgorin discs for eigenvalues with the following function
% 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)
A = [sqrt(-1) sqrt(2); sqrt(2) sqrt(-1)];
error(nargchk(nargin,1,1));
if size(A,1) ~= size(A,2)
error('Matrix should be square');
return;
end
% 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
r=0;
for j=1:size(A,1)
if i ~= j
r=r+(norm(A(i,j)));
end
end
% We try to make a vector of points for the circle:
N=256;
t=(0:N)*2*pi/N;
% 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,'+');
end
% 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:
ev=eig(A);
for i=1:size(ev)
rev=plot(real(ev(i)),imag(ev(i)),'ro');
end
hold off;
legend(rev,'Actual Eigenvalues',,'+');
xlim([-3 3]);
ylim([-3 3]);
end
how do i include the center point and the circle in the legend?
0 Comments
Accepted Answer
dpb
on 23 Oct 2016
Save the handles when you plot them--
...
hLCirc=plot(r*cos(t)+h, r*sin(t)+k ,'-');
hold on;
hLCntr=plot(h, k,'+');
...
legend([hLCirc hLCntr rev],'Circle','Center','Actual Eigenvalues',,'+');
See
doc legend % for more concise ways to write the legend text w/ cellstr arrays, etc., ...
More Answers (0)
See Also
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!