Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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..

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 23 Mag 2014
Modificato: Azzi Abdelmalek il 23 Mag 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by