(a + b) + c ≠ a + (b + c)
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
peluca6
il 30 Ago 2018
Modificato: David Goodmanson
il 30 Ago 2018
I'm new to Matlab
Is there any way to find a, b and c so that (a + b) + c ≠ a + (b + c) I know addition is not associative in floating point, but is there any way to do that in Matlab?
0 Commenti
Risposta accettata
David Goodmanson
il 30 Ago 2018
Modificato: David Goodmanson
il 30 Ago 2018
Hi peluca6,
try 0.1 0.2 0.3
These situations are not hard to find. If you just take three random floating point numbers between 0 and 1,
a = rand
b = rand
c = rand
(to make a vector or matrix of random numbers, see 'help rand') and take a look at the quantity
((a+b)+c) - (a+(b+c))
it is nonzero about 17% if the time.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!