-2

I have to plot the function f(x) = ln(20 - e^x) in Octave, and I use the command:

x = -5:0.1:5; 
y = log(20 - exp(x));
plot(x,y)

But the graph is not correct, because when I check in Wolfram Alpha it is not the same. Any help is appreciated!

enter image description here

Community
  • 1
  • 1
mandella
  • 180
  • 1
  • 17

1 Answers1

2

You plotted in Octave ln(20-e^x):

enter image description here

whereas what you put into Wolfram Alpha was e^x + e^y = 20, which looks like this:

enter image description here

Which is the exact same. The only difference here is that for e^x+e^y=20 Wolfram Alpha plots only the real solution (the blue line), whereas for ln(20-e^x) both Wolfram Alpha and Octave plot the full set of solution, so including imaginary solutions (although Octave plots only the real part of the complex solution).

If you look carefully you see that for x<ln(20)the imaginary part shown in Wolfram Alpha is 0, whereas for x>ln(20) there's an imaginary part (incidentally of y=ln(20)). Octave just plots only the real parts, as it ignores imaginary parts when plotting a complex signal. Just check whos y on your command line and it'll tell you it is a complex variable.

I'm on MATLAB, but your console output should be the similar:

>> x = -5:0.1:5; 
y = log(20 - exp(x));
plot(x,y)
Warning: Imaginary parts of complex X and/or Y arguments ignored 
>> whos y
  Name      Size             Bytes  Class     Attributes

  y         1x101             1616  double    complex 

which tells you A) when you plot the function that it is a complex signal and B) that y is indeed complex, as it should be for values of x>ln(20).

Adriaan
  • 17,741
  • 7
  • 42
  • 75