numerical error when dividing some identical complex number
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Misun Kim
am 2 Nov. 2022
Beantwortet: Misun Kim
am 3 Nov. 2022
I wanted to calculate the angular difference (e.g. 155 deg vs. 20 deg) by dividing the exponential angular representation (exp(1j*theta1)./exp(1j*theta2) to achieve this goal. While doing this, I found some numerical error for certain complex number.
For instance, exp(1j*0.5)./exp(1j*0.5)=1 (as it should be be). However, exp(1j*0.5166)./exp(1j*0.5166)=1.000+ 4.8e-17j. The imaginary component is tiny, but non-zero. It seems like a numerical precision issue. I can fix the problem by applying some threshold, but I'm just curious why this problem occurs only in some number, and not all complex number. Does anyone know it? Just out of curiosity.
Here is my MATLAB version info
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.13.0.2049777 (R2022b)
Operating System: Linux 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
Thanks!
Misun
2 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 2 Nov. 2022
Are you certain the two numbers you're using are identical down to the last bit, not just down to the last displayed digit?
x = 0.1234
y = 0.12341
Despite x and y being displayed the same, they are not the same stored value. False is the correct answer for this comparison that checks the stored value not the display.
areTheyIdentical = x == y
Does that small difference between x and y make a difference in the exponentials?
ex = exp(1i*x)
ey = exp(1i*y)
They display the same, but is the answer exactly 1? No.
ex/ey
Let's display the three values with a few more decimal places
format longg
[ex; ey; ex/ey]
That small difference between x and y resulted in a difference in ex and ey.
3 Kommentare
Walter Roberson
am 2 Nov. 2022
More compactly:
format long g
x=0.5166
ex = exp(1i*x)
ex./ex
This is not what I would have expected
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!