Vector Dot Product using Matrix
165 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
As we all know, the dot product of 2 vectors must be a scalar quantity. I have two vectors P and Z and they both have 6138 data points. So i converted them to Matrix of dimension 6138x3. Now when I used dot(P,Z) I am getting a 1x3 matrix. My question is how can I get the scalar quantity from this? Or Is there other way to the dot product of these two vectors using MATLAB.
THX
4 commentaires
Stephen23
le 10 Mar 2021
Modifié(e) : Stephen23
le 10 Mar 2021
"Now how can i get the dot products of these 2 vectors."
Given that vectors are (by definition) specified by just two points, I don't see how your 6138 data points define just two vectors. Can you explain how those two vectors are defined by so many data points?
"I meant P and Z both has 3 components of x,y,z . Thats why I converted it into matrix of 6138x3"
You can specify the dimension argument to get the dot product of all 6138 pairs of vectors:
A = rand(6138,3);
B = rand(6138,3);
V = dot(A,B,2)
Réponses (2)
Sai Veeramachaneni
le 12 Mar 2021
Hi,
For multidimensional arrays, dot function calculates the dot product of corresponding vectors along the first array dimension whose size does not equal 1.
In your case I think sum(dot(A,B)) works for you.
Hope it helps.
0 commentaires
Real User
le 6 Fév 2023
Modifié(e) : Real User
le 6 Fév 2023
You have 6138 R^3 vectors in A and also in B (your coordinates of each vector run along the 2nd dim):
A = rand(6138,3);
B = rand(6138,3);
You want to get 6138 dot products:
[dot(A(1,:),B(1,:)); dot(A(2,:),B(2,:)); ...]
so write
dot(A,B,2) %the "2" says that the coordinates of each vector in A or B
% run along the second dim (the one with length 3).
%Note: "dot" is the conjugated inner product.
(Alternatively, originally have A=rand(3,6138) etc. or use its transpose A.'; similarly for B. Then dot(A,B) works. OR dot(A,B).', if you want to output a column vector, as above.)
If, instead, you want all 6138*6138 dot products, write:
A'*B %or A.'*B if you want the non-conjugating inner product. No difference if A & B are real.
[Credit to Jan & Stephen above.]
0 commentaires
Voir également
Catégories
En savoir plus sur GPU Computing 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!