dot product between system of vectors

조회 수: 21 (최근 30일)
bidlee devi
bidlee devi 2020년 1월 26일
댓글: Turlough Hughes 2020년 1월 26일
Suppose we have a system of vectors Z and Y of size 3 *3 consisitng of three column vectors with three tuples in each colunm.
Z=[45 33 37 ; 39 28 37 ;35 36 48 ]
Y=[ 29.5 30 30 ;29.51 30 30 ;29.51 30 29 ]
How to write a matlab code to get Q of size 3*3 given by
Q=[10000.88925 9410.822 10295.99 ;10001.81888 9411.39 10296.72 ;10000.49116 9410.226 10295.24 ]
Here, in Q , element in (1,1) is a dot product between first column of Z and first column of Y. Likewise element in (2,1) is a dot product of second column of Y and first column of Z so on element (3,1) is a dot product between first column of Z and third column of Y. In this way, the first column of Q is formed. Moreover, for example, element (2,3) is a dot product between second column of Y and third column of Z and so forth
Can anyone help me out on how to automate this using matlab codes ? urgently needed.
Thanks in advance.
  댓글 수: 1
Stephen23
Stephen23 2020년 1월 26일
편집: Stephen23 2020년 1월 26일
Your example output values appear to be incorrect:
>> Y.'*Z
ans =
3511.2 2862.1 3599.8
3570.0 2910.0 3660.0
3535.0 2874.0 3612.0

댓글을 달려면 로그인하십시오.

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 1월 26일
How you are getting these values for Q? If you calculate the dot product between the colums of the variables you give the values are different, maybe you had a small error on your code? Back to your question this is basically a transpose matrix multiplication. A normal matrix multiplication is basically the dot product between rows and columns, if you transpose the first matrix you get the dot product of columns and columns, as you want. As example:
Z=[45 33 37 ; 39 28 37 ;35 36 48 ];
Y=[ 29.5 30 30 ;29.51 30 30 ;29.51 30 29 ];
A1 = zeros(3);
% Loop to do column dot product
for idxX = 1:3
for idxY = 1:3
A1(idxX,idxY) = dot(Z(:,idxX),Y(:,idxY));
end
end
A2 = Z'*Y; % Transpose matrix multiplication
A1
A2
norm(A1-A2)
A1 =
1.0e+03 *
3.5112 3.5700 3.5350
2.8621 2.9100 2.8740
3.5999 3.6600 3.6120
A2 =
1.0e+03 *
3.5112 3.5700 3.5350
2.8621 2.9100 2.8740
3.5998 3.6600 3.6120
ans =
6.4311e-13
  댓글 수: 2
bidlee devi
bidlee devi 2020년 1월 26일
Thank you.
Turlough Hughes
Turlough Hughes 2020년 1월 26일
Q = Z.'*Y
is actually the transpose of what was described, the correct answer is:
Q = Y.'*Z

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Turlough Hughes
Turlough Hughes 2020년 1월 26일
편집: Turlough Hughes 2020년 1월 26일
Based on your description you can do the following, transpose the Y and then it's a straight forward case of matrix multiplication
Q = Y.'*Z;
Though your description doesn't match the results you provide in Q. For example the dot product of the first columns is not 10000.88925
dot(Z(:,1),Y(:,1))

bidlee devi
bidlee devi 2020년 1월 26일
thank you. will check.

bidlee devi
bidlee devi 2020년 1월 26일
Thanks. will do it again.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by