plotting piecewise functions with logarithm
6 views (last 30 days)
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 on 27 Jan 2015
If the input vector X is negative, log produces complex result. Try the following version :
John D'Errico on 27 Jan 2015
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.