Problem with cubic root

8 ビュー (過去 30 日間)
Chesus
Chesus 2023 年 9 月 10 日
コメント済み: Bruno Luong 2023 年 9 月 11 日
When I try to get the cubic root of -1 (which should be -1) I get this:
(-1).^(1/3)
ans = 0.5000 + 0.8660i
How do I fix this?
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 10 日
What is there to fix? That is one of the 3 cube roots of -1.
Do you wish to obtain -1 as the output?

サインインしてコメントする。

採用された回答

Sam Chak
Sam Chak 2023 年 9 月 10 日
nthroot(-1, 3)
ans = -1
  4 件のコメント
Walter Roberson
Walter Roberson 2023 年 9 月 10 日
編集済み: Walter Roberson 2023 年 9 月 10 日
I put in the condition that when A is negative
A = -rand(1,1e6) * 100000;
l1 = log(A);
l2 = log(-A) + log(-1);
nnz(l1 ~= l2)
ans = 0
Bit for bit equality.
Bruno Luong
Bruno Luong 2023 年 9 月 11 日
I know it is true for negative A, but readers might wonder out the blue where this come from: "log(A) is log(-A)+log(-1)"?
And next why log(-1) is 1i*pi (and not -1i*pi)? Of course one can check it with MATLAB command.
The MATLAB log doc states
log(A) = log(abs(A)) + 1i*angle(A)
why not start with that?
And btw log(A) = log(abs(A)) + 1i*angle(A) is not entirely true either in some special values of A.

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by