How to stem plot a complex function in matlab?
13 views (last 30 days)
Show older comments
Stem plot the following function[Plot the imaginary and real parts seperately]: e^(x*j*pi*) for (x>=5 && x<=11): my solution: x=5:11; y=exp(j*pi*x); figure(1); stem(x,real(y)); figure(2); stem(x,imag(y));
I got two graphs but I am not sure if there are correct. Let me know if there is a mistake or a neater way to approach it?
0 Comments
Answers (1)
Dimitris Kalogiros
on 25 Jul 2018
Hello
You can try this piece of code:
clc;
close all;
x=5:.05:11;
y=exp(1i*pi*x);
plot3(x, zeros(size(x)), zeros(size(x)), '-k');
xlabel('x'); ylabel('real(y)'); zlabel('imag(y)');
axis square; zoom on; grid on; hold on;
for k=1:length(x)
plot3([x(k) x(k)],[0 real(y(k))],[0 imag(y(k))],'-b');
plot3(x(k), 0, 0,'b.');
plot3( x(k), real(y(k)), imag(y(k)), 'b*');
end
hold off
It repsesents complex numbers as 3D vectors.
Personally, when I deal with complex numbers, I use to visualize them as real and imag part on the same graph:
clc;
close all;
x=5:.05:11;
y=exp(1i*pi*x);
figure;
stem(x, real(y), 'bo'); hold on;
stem(x, imag(y), 'r*');
zoom on; grid on; xlabel('x');
legend('real', 'imaginary');
hold off
0 Comments
See Also
Categories
Find more on 2-D and 3-D 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!