High dimension matrix summation: a + b != b + a
Show older comments
I have two matrices X1 and X2. Both are 10x15x10x10 dimensions. There are three scalars:
,
and
.
Let i={i1,i2,i3,i4} denote the index of an element. For elements with the same index in X1 and X2, say X1(i) and X2(i), I want to compute a simple weighted sum:
Since the γ's are all scalars, I think I can do this multiplication and summation at the matrix level and get the result as a 10x15x10x10 matrix. However, when I change the order of summation, the results are also different. That is:
A =
+
*X1 +
*X2;
B =
+
*X2 +
*X1;
The differences in all entries of A and B sum up to 2.3856e-12. However, since this is just element-wise summation, A and B should be exactly the same.
Can someone explain what is going wrong?
I do notice that if I take out
, I get the same answer... Why does adding a constant affect the final result?
Please see attached for the sample data and codes.
Thank you for your help!!
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!