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

1 Ansicht (letzte 30 Tage)
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..

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 23 Mai 2014
Bearbeitet: Azzi Abdelmalek am 23 Mai 2014
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by