dot product between system of vectors

11 ビュー (過去 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 Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by