Ploting, Imaginary parts of complex X and/or Y arguments ignored

I have question.
I want to plot function plot(x,f(x)), but f(x) has some complex values for some values of x. When I want to plot this function, I receive report ''Imaginary parts of complex X and/or Y arguments ignored''.
How to solve this problem, because I want to plot f(x) for all values, not just real?
Thank you very much for any answer.
Regards,
Nikola

Answers (2)

What would you like the output to look like at the f(x) that are imaginary?
plot() has not ignored any points: it has done the equivalent of
plot(x, real(f(x)))
on your behalf.
Perhaps you would like something such as
fx = f(x);
plot(x, real(fx), 'b', x, imag(fx), 'r');

2 Comments

why you have written 'b' and 'r' here?
'b' and 'r' are color codes, blue and red, so that the real and imaginary parts can be distinguished at a glance.

Sign in to comment.

You can either add another dimension to yuor plot (another line or plot3) and extract the imaginary parts (using imag()) or you can convert to real using abs())

Asked:

on 23 Feb 2012

Commented:

on 8 Oct 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!