Dot product of a column vector by its own elements

5 views (last 30 days)
Hi, I have a matrix containing coordinates(x,y,z) and I am trying to find the dot product of the elements inside the vector. The matrix looks like this:
% a(x) a(y) a(z)
-0.0022 -0.0131 0.9999
% b(x) b(y) b(z)
-0.8062 0.2794 0.5216
% c(x) c(y) c(z)
-0.9325 0.0547 -0.3570
I want to achieve a dot product matrix of something like this:
a.a a.b a.c
b.a b.b b.c
c.a c.b c.c
I tried writing a code
Dot_P(1,1)= dot(matrix(1,:),matrix(1,:));
Dot_P(1,2)= dot(matrix(1,:),matrix(2,:));
Dot_P(1,3)= dot(matrix(1,:),matrix(3,:));
but this is hard coding and is not efficient, any help is appreciated!
  2 Comments
Jan
Jan on 7 Feb 2018
Edited: Jan on 7 Feb 2018
The question is not clear. You want to achieve a matrix, but post a hard coded version to create a vector.
Please post the inputs such that they can be used by copy&paste to suggest a solution. This is more convenient for the ones who want to help you.
Goh Jia Man
Goh Jia Man on 7 Feb 2018
Sorry for the confusion, let's say I have a [m x 1] matrix, I want to create a new symmetric square matrix, which has the form of
m1.m1 m1.m2 m1.m3
m2.m1 m2.m2 m2.m3
m3.m1 m3.m2 m3.m3

Sign in to comment.

Accepted Answer

Jan
Jan on 7 Feb 2018
Edited: Jan on 7 Feb 2018
With some guessing:
X = [-0.0022, -0.0131, 0.9999; ...
-0.8062, 0.2794, 0.5216; ...
-0.9325, 0.0547, -0.3570];
P = X * X.'
Now your "c" is X(1, :). Then e.g. P(3,3) equals c * c'.
  1 Comment
Goh Jia Man
Goh Jia Man on 7 Feb 2018
Oh thank you so much! I was cracking my head as to how do I use the dot(A,B) function to achieve the matrix

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 7 Feb 2018
a=[-0.0022 -0.0131 0.9999];
b=[-0.8062 0.2794 0.5216];
c=[-0.9325 0.0547 -0.3570];
M=[a;b;c]
M*M'

Community Treasure Hunt

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

Start Hunting!