Why do I get the wrong value when I try to evaluate log([-1;1]) this way?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Farouk Moukaddem
el 9 de Nov. de 2017
Respondida: Viggnesh Venkatakrishnan
el 17 de Dic. de 2018
I get different results in MATLAB R2017a when I perform the same operation in different ways:
>> v = -1 + 1i; >> log([0;0]./v-1)
ans =
0.0000 - 3.1416i
0.0000 - 3.1416i
This is incorrect
On the other hand, doing the following shows correct output: >> log([0;0]./(-1 + 1i)-1)
ans =
0.0000 + 3.1416i
0.0000 + 3.1416i
This is correct
1 comentario
Star Strider
el 9 de Nov. de 2017
It was apparently fixed in R2017b:
v = -1 + 1i;
log([0;0]./v-1)
log([0;0]./(-1 + 1i)-1)
ans =
0 + 3.1416i
0 + 3.1416i
ans =
0 + 3.1416i
0 + 3.1416i
Respuestas (2)
Viggnesh Venkatakrishnan
el 17 de Dic. de 2018
Hi Farouk,
I understand that you are getting different results in MATLAB R2017a when you perform the below operation in different ways:
% way 1
>> v = -1 + 1i; >> log([0;0]./v-1)
% way 2
>> log([0;0]./(-1 + 1i)-1)
This is a known issue with MATLAB R2017a where there is inconsistency in handling real values stored in a complex array for log, log2, log10, and log1p. This is a link to the External Bug Report : https://www.mathworks.com/support/bugreports/details/1653779
This issue has been fixed in R2017b.
Thanks and Regards,
Viggnesh Venkatakrishnan
0 comentarios
Roger Stafford
el 9 de Nov. de 2017
Editada: Roger Stafford
el 9 de Nov. de 2017
Both answers are correct for log(-1). In fact there are infinitely many possible correct answers of the form (2*n+1)*pi*i for any integer n, positive or negative. In mathematics the logarithm function is said to have infinitely many “branches”. If you started with z = 1 and moved z continuously in the complex plane in a circle around the origin as center in the counterclockwise direction you would arrive at pi*i for log(-1). However, if you moved clockwise instead, you would arrive at -pi*i. If you continued around multiple times you would get all those other possible values.
0 comentarios
Ver también
Categorías
Más información sobre Debugging and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!