how to distinguish between four zeros in matlab plotting
7 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Voss
on 27 Mar 2022
Something 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('Zero #%d',ii), ...
'VerticalAlignment','top','HorizontalAlignment','center');
end
2 Comments
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
sprintf('\\zeta #%d',3) % \\ becomes \ (so that \\zeta becomes \zeta, which is then used in text())
More Answers (0)
See Also
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!