dot product between system of vectors

13 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 26 Jan 2020
Edited: Stephen23 on 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

Sign in to comment.

Accepted Answer

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 Comments
Turlough Hughes
Turlough Hughes on 26 Jan 2020
Q = Z.'*Y
is actually the transpose of what was described, the correct answer is:
Q = Y.'*Z

Sign in to comment.

More Answers (3)

Turlough Hughes
Turlough Hughes on 26 Jan 2020
Edited: Turlough Hughes on 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 on 26 Jan 2020
thank you. will check.

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

Community Treasure Hunt

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

Start Hunting!