how to distinguish between four zeros in matlab plotting

7 views (last 30 days)
I ploted the zeros of the function f(z), where z is a complex number and its rootes are complex numbers. for example
When f(z) has 4 zeros move in the complex plane with time t. How can I write the name of these zeros on their graph to show the movement of each zero in the complex plane. (I mean How do I distinguish zeros from each other?) on the graph.
Thank you very much

Accepted Answer

Voss
Voss on 27 Mar 2022
Something like this?
% get some complex numbers, z:
f = [1 2 3 4 5];
z = roots(f)
z =
-1.2878 + 0.8579i -1.2878 - 0.8579i 0.2878 + 1.4161i 0.2878 - 1.4161i
% plot z on the complex plane and label them as 'Zero #1', etc.:
figure();
x = real(z);
y = imag(z);
for ii = 1:numel(z)
plot(x(ii),y(ii),'ko');
hold on
text(x(ii),y(ii),sprintf('Zero #%d',ii), ...
'VerticalAlignment','top','HorizontalAlignment','center');
end
  2 Comments
Aisha Mohamed
Aisha Mohamed on 10 Apr 2022
Hi Dear
Thank you very much this answer is work, could you please let me know how can I write (zeta) instead of zero in the figure ? because when I wrote:
text(x(ii),y(ii),sprintf('\zeta #%d',ii), ...
zeta did not appeare in the figure?
I will appreciate any help
Thank you.
Voss
Voss on 11 Apr 2022
@Aisha Mohamed Because the "\zeta" is part of the first argument to sprintf (i.e., the string format specification), the backslash will be treated as a special character for sprintf. In order to avoid that and just have the backslash be a backslash, so that it is correctly interpreted as "\zeta" by the text function, use a double-backslash to tell sprintf to ignore the backslash. It looks like this:
% get some complex numbers, z:
f = [1 2 3 4 5];
z = roots(f);
% plot z on the complex plane and label them as 'Zero #1', etc.:
figure();
x = real(z);
y = imag(z);
for ii = 1:numel(z)
plot(x(ii),y(ii),'ko');
hold on
text(x(ii),y(ii),sprintf('\\zeta #%d',ii), ...
'VerticalAlignment','top','HorizontalAlignment','center');
end
Here's the result from sprintf in both cases, for your reference:
sprintf('\zeta #%d',3) % \z doesn't mean anything to sprintf
Warning: Escaped character '\z' is not valid. See 'doc sprintf' for supported special characters.
ans = 1×0 empty char array
sprintf('\\zeta #%d',3) % \\ becomes \ (so that \\zeta becomes \zeta, which is then used in text())
ans = '\zeta #3'

Sign in to comment.

More Answers (0)

Categories

Find more on Line 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!