why does Matlab not expand(abs(a-b)^2) ?

4 ビュー (過去 30 日間)
Niklas Kurz
Niklas Kurz 2020 年 10 月 14 日
編集済み: Niklas Kurz 2020 年 10 月 18 日
Wolfram alpha shows: a^2 -2*a*b+b^2

採用された回答

Walter Roberson
Walter Roberson 2020 年 10 月 14 日
>> a=complex(rand,rand)
a =
0.0975404049994095 + 0.278498218867048i
>> b=complex(rand,rand)
b =
0.546881519204984 + 0.957506835434298i
>> abs(a-b)^2
ans =
0.662960138288077
>> a^2-2*a*b+b^2
ans =
-0.259145264457063 + 0.610212976647027i
  2 件のコメント
Niklas Kurz
Niklas Kurz 2020 年 10 月 18 日
編集済み: Niklas Kurz 2020 年 10 月 18 日
Hence it's incorrect for complex numbers. Alrigth. But for real numbers it should work. However
expand(abs(real(a)-real(b))^2
still doesn't expand.
Walter Roberson
Walter Roberson 2020 年 10 月 18 日
expand(simplify(abs(real(a) -real(b) ) ^2))

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

その他の回答 (0 件)

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by