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 Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 8월 23일

댓글:

2019년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by