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

조회 수: 2 (최근 30일)
Esfandiar Farahvashi
Esfandiar Farahvashi 2019년 3월 29일
편집: Guillaume 2019년 3월 29일
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
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
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
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 CenterFile 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