MATLAB: Sum(c*b,’a​ll’)>sum(c​)*sum(b)

dyadic productMATLABsum

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?

Best Answer

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
Related Question