numerical error when dividing some identical complex number

조회 수: 4 (최근 30일)
Misun Kim
Misun Kim 2022년 11월 2일
답변: Misun Kim 2022년 11월 3일
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

채택된 답변

Misun Kim
Misun Kim 2022년 11월 3일
@Paul provides the link to the previous discussion which answers to my question on dividing complex number. For the ease of finding it, I place the link here again. https://www.mathworks.com/matlabcentral/answers/548010-why-is-a-number-divided-by-itself-not-equal-to-unity

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 11월 2일
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
x = 0.1234
y = 0.12341
y = 0.1234
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
areTheyIdentical = logical
0
Does that small difference between x and y make a difference in the exponentials?
ex = exp(1i*x)
ex = 0.9924 + 0.1231i
ey = exp(1i*y)
ey = 0.9924 + 0.1231i
They display the same, but is the answer exactly 1? No.
ex/ey
ans = 1.0000 - 0.0000i
Let's display the three values with a few more decimal places
format longg
[ex; ey; ex/ey]
ans =
0.992395876704891 + 0.123087058211376i 0.992394645784689 + 0.123096982163989i 0.99999999995 - 9.99999999984743e-06i
That small difference between x and y resulted in a difference in ex and ey.
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 11월 2일
More compactly:
format long g
x=0.5166
x =
0.5166
ex = exp(1i*x)
ex =
0.869503552901398 + 0.493926686353193i
ex./ex
ans =
1 + 4.82671432212255e-17i
This is not what I would have expected
Paul
Paul 2022년 11월 2일
Check the link in the comment to the Question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by