(a + b) + c ≠ a + (b + c)

조회 수: 8 (최근 30일)
peluca6
peluca6 2018년 8월 30일
편집: David Goodmanson 2018년 8월 30일
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?

채택된 답변

David Goodmanson
David Goodmanson 2018년 8월 30일
편집: David Goodmanson 2018년 8월 30일
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개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by