Inconsistent results in Matrix-vector-multiplication?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dear all,
I was analyzing the results of a matlab code where I found a strange inconsistency in a matrix and vector multiplication operation.
I have a matrix as:
M= [ -0.499999999999999, -0.866025403784439 , 0; 0.866025403784439, -0.499999999999999, 0; 0 , 0 , 1.000000000000000];
And a vector as:
V = [ 1.351250000000000; 2.340433653727400; 0];
Now if a simply multiply them I receive the following vector:
RES1 = [-2.702499999999961, 2.565324651410645e-14, 0];
However, if I execute the following command (which should actually reproduce the same results as RES1(2) due to matrix and vector multiplication rule):
RES2 = M(2,:) * V
I receive a different result as expected:
RES2 = 2.575717417130363e-14;
This means that RES1(2) != RES2 which should not happen actually from a mathematical point of view (if I an not wrong…).
Is this because of somewhat precision error?
Thank you for your help,
Kind regards
1 Kommentar
Guillaume
am 29 Mär. 2019
How did you obtain RES1?
M= [ -0.499999999999999, -0.866025403784439 , 0; 0.866025403784439, -0.499999999999999, 0; 0 , 0 , 1.000000000000000];
V = [ 1.351250000000000; 2.340433653727400; 0];
>> format longg
>> RES1 = M*V
RES1 =
-2.70249999999996
2.57571741713036e-14
0
>> RES2 = M(2, :) * V
RES2 =
2.57571741713036e-14
>> sum(M(2, :) .* V.')
ans =
2.57571741713036e-14
Antworten (1)
Matt J
am 29 Mär. 2019
Bearbeitet: Matt J
am 29 Mär. 2019
The order of the summation steps in the matrix multiplication may be slightly different when you execute the computation in two different ways, resulting in small floating point approximation differences.
1 Kommentar
Guillaume
am 29 Mär. 2019
Bearbeitet: Guillaume
am 29 Mär. 2019
Yes, also note that considering the magnitude of the numbers that 2e-14 is for all intent and purpose just 0. See that the two values summed to obtain that result are more or less the opposite of each other:
>> M(2, :) .* V'
ans =
1.17021682686372 -1.1702168268637 0
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!