plotting piecewise functions with logarithm
5 次查看（过去 30 天）
回答： John D'Errico ，2015-1-27
I am plotting a piecewise function as in below:
The thing is, I get an error message "Warning: Imaginary parts of complex X and/or Y arguments ignored > In pcwise at 8 "
And the graph does not show the correct plots. (How could there by complex values for a log function?) Please help. Thanks
Youssef Khmou 2015-1-27
If the input vector X is negative, log produces complex result. Try the following version :
John D'Errico 2015-1-27
How could there be complex values for a log function? Um, what is the log(-2)? Or ANY negative number for the argument?
0.693147180559945 + 3.14159265358979i
So what are you doing?
g is 5, and x_axis varies from -40 to 40.
So to me, it looks like you are trying to evaluate the log of a negative number.
Part of your problem arises from the fact that an if statement does NOT apply separately to every member test you give it. For example, this does not do what you apparently think it does:
x = 1:10;
if x < 5
Perhaps you are confusing it with something that does do what you want:
for x = 1:10
if x < 5
In the first example I showed, x is a vector. In the second, x is a scalar, that sequentially takes on values from 1 to 10.
Find more on Graphics Performance 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!