Inconsistent results in Matrix-vector-multiplication?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Guillaume
2019 年 3 月 29 日
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
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 件のコメント
Guillaume
2019 年 3 月 29 日
編集済み: Guillaume
2019 年 3 月 29 日
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
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!