Effacer les filtres
Effacer les filtres

dot product between system of vectors

8 vues (au cours des 30 derniers jours)
bidlee devi
bidlee devi le 26 Jan 2020
Commenté : Turlough Hughes le 26 Jan 2020
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 commentaire
Stephen23
Stephen23 le 26 Jan 2020
Modifié(e) : Stephen23 le 26 Jan 2020
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

Connectez-vous pour commenter.

Réponse acceptée

Thiago Henrique Gomes Lobato
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 commentaires
bidlee devi
bidlee devi le 26 Jan 2020
Thank you.
Turlough Hughes
Turlough Hughes le 26 Jan 2020
Q = Z.'*Y
is actually the transpose of what was described, the correct answer is:
Q = Y.'*Z

Connectez-vous pour commenter.

Plus de réponses (3)

Turlough Hughes
Turlough Hughes le 26 Jan 2020
Modifié(e) : Turlough Hughes le 26 Jan 2020
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 le 26 Jan 2020
thank you. will check.

bidlee devi
bidlee devi le 26 Jan 2020
Thanks. will do it again.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by