Vector Dot Product using Matrix
163 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2021 年 3 月 10 日
編集済み: Stephen23
2021 年 3 月 10 日
"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)
回答 (2 件)
Sai Veeramachaneni
2021 年 3 月 12 日
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 件のコメント
Real User
2023 年 2 月 6 日
編集済み: Real User
2023 年 2 月 6 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!