Why do I get the wrong value when I try to evaluate log([-1;1]) this way?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Star Strider
2017-11-9
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
回答(2 个)
Viggnesh Venkatakrishnan
2018-12-17
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 个评论
Roger Stafford
2017-11-9
编辑:Roger Stafford
2017-11-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!