exp( ) gives unexpected answer for (2,2) input

4 visualizaciones (últimos 30 días)
Jonathon Cheah
Jonathon Cheah el 2 de Sept. de 2022
Editada: Bruno Luong el 9 de Sept. de 2022
I have trouble understanding the results returned by exp():
given a= [1.4142 1.4121; 1.4142 1.4121] ;
exp(j*2*pi*a*10^3) = [0.2269 +0.9739i 0.8312+0.5560i ; 0.2269+0.9739i 0.8312+0.5560i]
but checking by elements:
exp(j*2*pi*1.4142*10^3)=0.3090+0.9511i
exp(j*2*pi*1.4121*10^3)=0.890+0.5878i
if a =[1.4142 1.4121];
then the answers agree with the element check. What am I missing?
  1 comentario
James Tursa
James Tursa el 2 de Sept. de 2022
Editada: James Tursa el 2 de Sept. de 2022
Please show the actual code ... i.e., copy & paste the code and actual MATLAB output. It could be that you hand typed in numbers based on MATLAB truncated display but the actual numbers used by MATLAB are different. E.g., what does 1.4142-a(1,1) and 1.4141-a(1,2) show? Or use format longg and display the "a" matrix again.

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 2 de Sept. de 2022
Editada: John D'Errico el 2 de Sept. de 2022
I would bet a large sum of money that a is not exactly what you think it is.
a_you_think = [1.4142 1.4121; 1.4142 1.4121];
However, the odds are instead very good that those numbers are only rounded to 5 significant digits, then they were displayed as such. Remember that MATLAB carries roughly 16 significant digits in a double precision number. So that value of 1.4142 for a(1,1) could be anything in the interval (1.41415,1.41425).
a11 = [1.41415*(1+eps);1.41425*(1- eps)]
a11 = 2×1
1.4142 1.4142
format long g
exp(j*2*pi*a11*10^3)
ans =
0.587785252291231 + 0.80901699437585i 1.67332990617082e-12 + 1i
So is your output unexpected? It is only unexpected for YOU. I'm not at all surprised.
  6 comentarios
Jonathon Cheah
Jonathon Cheah el 9 de Sept. de 2022
Bruno was pointing out my 2 numbers (1.414213562373095-1.412093835408965) x10^3 being large enough for many "turns" (cycles?) which is true, but I was referring to each single number 1.414213562373095 with 1.4142 as an example. Knowing Euler identity exp(ix)=cos(x)+isin(x), how big x is, is moot by mod(x,2pi). I asked for answer because I was blindsighted by Matlab's 16 significant digits as John D'Errico pointed out, and I think James Tursa was going the same direction. Indeed, when mod(x,2pi) ~ 0 or pi for sine for exampe, tiniest delta will give relatively bigger swing in answers. I expected that, but not by not knowing the inherent Matlab number resolutions. The factor x10^3 is necessary but not sufficient effects in my "small" delta comment. I hope this clears up the confusions.
Bruno Luong
Bruno Luong el 9 de Sept. de 2022
Editada: Bruno Luong el 9 de Sept. de 2022
@Jonathon Cheah "The factor x10^3 is necessary but not sufficient effects in my ""small" delta comment.
The factor 10^3 + truncating digits of 1.414213562373095 are perfectly sufficient to explain. There is noting mysterious as you seem to imply.
Here are two numbers
a=1.414213562373095
a = 1.4142
ar=1.4141
ar = 1.4141
Now the exponential values with factor 10^3
z=exp(1i*2*pi*a*10^3)
z = 0.2269 + 0.9739i
zr=exp(1i*2*pi*ar*10^3)
zr = 0.8090 + 0.5878i
Q: How much is the difference in angles after scaling by 10e3?
theta=2*pi*(ar-a)*10^3 % in radian
theta = -0.7135
A: And the angle error in degree,
thetadeg=rad2deg(theta) % in degres
thetadeg = -40.8825
OK the error of angle si about -40 degres, not quite one turn (=360 degres) but it is not small by any mean due solely to the factor 10^3, nothing else.
Q: Can I retreive the angle from z and zr alone?
A: Yes:
atan2(imag(zr/z),real(zr/z)) % compare with theta above
ans = -0.7135
Q: Does the error of angle can explain the different between z and zr
z*exp(1i*theta)
ans = 0.8090 + 0.5878i
zr
zr = 0.8090 + 0.5878i
A: Perfectly
To summarize:
There is nothing surprise when you take time to decompose and check the bound of the error.
There is no lesson to be learnsed other then checking how your calculation chain propagate the error.

Iniciar sesión para comentar.

Más respuestas (1)

Paul
Paul el 2 de Sept. de 2022
Seems to give the expected result?
a= [1.4142 1.4121; 1.4142 1.4121]
a = 2×2
1.4142 1.4121 1.4142 1.4121
exp(j*2*pi*a*10^3)
ans =
0.3090 + 0.9511i 0.8090 + 0.5878i 0.3090 + 0.9511i 0.8090 + 0.5878i

Community Treasure Hunt

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

Start Hunting!

Translated by