Why summing a matrix in 2 different ways can give not the same numbers ??? Does anyone know?

1 次查看(过去 30 天)
I had a big problem with a code because of this mistake which looks silly but maybe it's not..
suppose
f1 = .4 ; f2 =.5199 ; f4 = 0.0267 ; f3 = 0.0534 ; Total_mass = 4.799844e+22; frac_mass = [f1,f2,f3,f4]*Total_mass ;
sum(frac_mass) == sum(frac_mass(4:-1:1)) gives me '0' (FALSE) as an answer.. if you check both numbers they are the same... but setting "format long" there's a factor 1 after some zeros when you check the right-hand statement above. Where does this "1" come from? I really thought the results should've been the same.. Need some help on it please..

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2014-5-23
编辑:Azzi Abdelmalek 2014-5-23
Because the summations are done in different order, look at this link http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Note that the results are slightly different

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by