필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Getting differnet answers fromMatlab for what looks like the same expression

조회 수: 1 (최근 30일)
John Wood
John Wood 2020년 3월 9일
마감: MATLAB Answer Bot 2021년 8월 20일
I am trying to raise a real number (or vector of real numbers) to a fractional power.
V = -10:0.1:80;
V0 = 8;
m = 0.323;
Vx = (1 + V/V0);
Vx(1)
ans =
-0.25
>> sprintf('%0.55f', Vx(1))
ans =
'-0.2500000000000000000000000000000000000000000000000000000'
>> (Vx(1))^.323
ans =
0.337319506343289 + 0.542770712359585i
sprintf('%0.55f', -0.25)
ans =
'-0.2500000000000000000000000000000000000000000000000000000'
>> -0.25^.323
ans =
-0.6390
Why is the power of one version of 0.25 real, and the other is complex, when both versions of "-0.25" are identical to 55 sf?

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 3월 9일
Try this and hope you know why
(-0.25)^.323
  댓글 수: 2
Steven Lord
Steven Lord 2020년 3월 9일
To be more explicit, the power and matrix power operators (.^ and ^ respectively) have higher precedence (level 2) than unary minus (the unary - operator) has (level 4.) See this page for the precedence breakdown. Parentheses are at level 1, which is why Fangjun Jiang's suggestion gives a complex result.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by