how can i do a multiplication between a column and a row?
6 views (last 30 days)
Show older comments
Jesus Francisco Serna Monsivais
on 3 Feb 2022
Edited: Jesus Francisco Serna Monsivais
on 23 Sep 2022
when i make a product between a column and a row it says that it is incosistent row / column dimensions
3 Comments
Voss
on 3 Feb 2022
Those are both row vectors. A comma and a space do the same thing in concatenation, e.g., when defining a vector/matrix.
To make a column vector you can use semicolons:
A = [2 3 4];
B = [-2; 1; 3];
A*B
B*A
Accepted Answer
KSSV
on 3 Feb 2022
A = [2 3 4] ;
B = [-2 1 3] ;
C1 = A*B' % If you are expecting a dot product betwee them
C2 = A.*B % element by element multiplication
C3 = A'*B % if you expecting a 3x3 matrix
0 Comments
More Answers (1)
Walter Roberson
on 3 Feb 2022
The * operator is for algebraic matrix multiplication, also known as inner product. When you take A*B then size(A,2) must be the same as size(B,1) and the result is size(A,1) by size(B,2) . For example,
A=[2;3;4], B=[-2,1,3]
size(A,2) == size(B,1)
C = A*B
[size(A,1), size(B,2)] == size(C)
So if you want to use the * operator between two row vectors of the same length, then you need to transpose one of the two. If you transpose the first of them then the result would be a square matrix; if you transpose the second of them then the result would be a scalar.
If you want to multiply A(1) by B(1) and A(2) by B(2) and so on, then that is not the * operator, it is the .* operator
A=[2,3,4], B=[-2,1,3]
C = A .* B
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!