numerical error when dividing some identical complex number
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Misun Kim
el 2 de Nov. de 2022
Respondida: Misun Kim
el 3 de Nov. de 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 comentarios
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 2 de Nov. de 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 comentarios
Walter Roberson
el 2 de Nov. de 2022
More compactly:
format long g
x=0.5166
ex = exp(1i*x)
ex./ex
This is not what I would have expected
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!