Inconsistent results in Matrix-vec​tor-multip​lication?

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 个评论

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

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2019-3-29
编辑:Matt J 2019-3-29
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 个评论

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

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by