Different complex log values displayed for a "single" input
Ältere Kommentare anzeigen
Hello fellow MATLAB experts.
I'm here to question the following MATLAB behaviour: we do know, thanks to Euler's identity, that
. Now, since complex exponential is a periodic function we do know that giving in input values that differ by an integer multiple of the period gives us in output the same value, which is, in this specific case, -1.
So it is true that
But it's also true that
And so on. So, natural logarithm of this function could give us any of these arguments as solution because it is true that for every argument in such form the complex exp's result is always -1.
This is kinda the problem: sometimes MATLAB's result of complex log is
, sometimes is
. From what I've seen, an example of this problem is:
. From what I've seen, an example of this problem is:So based on the argument being positive or negative i get two different, correct, results. Is there anything i can do to only get just one, say, the first one?
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 23 Okt. 2019
0 Stimmen
Which release of MATLAB are you using? If you're using a release prior to release R2017b, try upgrading to that release or later to see if the fix for Bug Report 1653779 resolves the issue.
6 Kommentare
Alessandro Buldini
am 24 Okt. 2019
Bearbeitet: Alessandro Buldini
am 24 Okt. 2019
Steven Lord
am 24 Okt. 2019
In that case can you show the exact code you're running where you see this difference? Include if possible the code you use to generate the inputs to the log function. If that code is too long or complicated, instead display the inputs you pass into the log function using the longg display format (format longg) or even better the hex display format (format hex) and paste that display into your response.
Alessandro Buldini
am 24 Okt. 2019
Alessandro Buldini
am 24 Okt. 2019
Steven Lord
am 24 Okt. 2019
Let's break your m function into two pieces.
f = @(x) exp(pi*1i+2*pi*1i*x);
m = @(x) log(f(x));
When you evaluate m(20) and m(-20) the sign of the imaginary part is different. Let's see the numbers that got passed into log in those two calls.
x20 = f(20)
xm20 = f(-20)
x20 has an imaginary part that's just barely positive (around 1.6e-14.) xm20 has an imaginary part that's just barely negative (around -8.3e-15.) Since one way to define the principal value of the logarithm involves computing the atan2 of the imaginary part and the real part, that difference in sign of the imaginary part means the atan2 of one is just less than pi while the other is just greater than -pi. You're seeing the "jump" behavior described at the end of the "Definition of principal value" section on that Wikipedia page.
Why do x20 and xm20 have nonzero imaginary parts? Aren't those just the sin of integer multiples of π by Euler's formula? No. They're the sin of integer multiples of pi. pi is close to, but not exactly equal to, π. While the sine of π is exactly 0, the sin of pi is not exactly 0. You might find this Cleve's Corner article interesting, especially the last screen or so.
Alessandro Buldini
am 25 Okt. 2019
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!