b=[0.4 0.4 0.1 0.1]
c=[0.6 0.4]'
sum(c*b,'all')>sum(c)*sum(b)
returns 1.
sum(c)=sum(b)=1, while sum(c*b,'all') seems to be larger than 1. Why is that?

 採用された回答

Matt J
Matt J 2019 年 8 月 23 日
編集済み: Matt J 2019 年 8 月 23 日

1 投票

Floating point discrepancies. You cannot count on floating point calculations giving a perfectly accurate result of 1 (unless they involve only integer arithmetic).
>> x=c*b; sum(x(:))-1
ans =
2.220446049250313e-16

1 件のコメント

Gergely Bunth
Gergely Bunth 2019 年 8 月 23 日
Thank you. Now I remember I should have known this.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by