Why do I get the wrong value when I try to evaluate log([-1;1]) this way?

조회 수: 2 (최근 30일)
Farouk Moukaddem
Farouk Moukaddem 2017년 11월 9일
답변: Viggnesh Venkatakrishnan 2018년 12월 17일
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
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
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

Roger Stafford
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.

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by