Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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..

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Mayo de 2014
Editada: Azzi Abdelmalek el 23 de Mayo de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by