Wrong result given by matrix multiplication
Mostrar comentarios más antiguos
I was doing a matrix multiplication with 3 matrices: BT * C * B
BT = [-1 0 3; 0 -3 -1; 4 0 -2; 0 -2 4; 1 0 3; 0 3 1; -4 0 2; 0 2 -4]
C = [32 8 0; 8 32 0; 0 0 12]
B = BT'
The result given by Matlab is:
>> BT * C * B
ans =
140 -12 -200 160 76 12 200 -160
-12 300 -72 144 -60 -300 72 -144
-200 -72 560 -160 56 72 -560 160
160 144 -160 320 128 -144 160 -320
76 -60 56 128 140 60 -56 -128
12 -300 72 -144 60 300 -72 144
200 72 -560 160 -56 -72 560 -160
-160 -144 160 -320 -128 144 -160 320
However, as I calculated the result by hand it gave me:
140 60 -56 -128 -140 -60 56 128
60 300 -72 144 -60 -300 72 -144
-56 -72 560 -160 56 72 -560 160
-128 144 -160 320 128 -144 160 -320
-140 -60 56 128 140 60 -56 -128
-60 -300 72 -144 60 300 -72 144
56 72 -560 160 -56 -72 560 -160
128 -144 160 -320 -128 144 -160 320
As you can see, Matlab gave wrong answers on
ans(2:end, 1)
and
ans(1, 2:end)
but correct on all the other elements ( i.e., ans(1, 1) and ans(2:end, 2:end) ) in the resulting 8-by-8 matrix.
I have checked my hand calculation several times and found nothing wrong in it.
Why do I get this weird behavior? Am I missing something?
Will be very appreciated if someone could correct/clarify me!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!