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!