MATLAB dot product

dot( ) command or function gives the dot or scalar product of vectors or matrices or arrays, after reading this MATLAB dot product topic, you will know the theory and examples.


Syntax:

dot(a,b)

  • a and b are two vectors.

Example: To find the dot product of two vectors.

% create two vectors A and B 
A=[3,20,34] 
B=[13,2,3]

dot(A,B)

Output:

A =

3  20  34

B =

13  2  3

ans =

181

Explanation:

  • the dot product of vectors A and B as A.B gives output 3*13+20*2+34*3 = 181.

Example: To find the dot product of two matrices.

% create two vectors A and B 
A=[3,20,34;2,3,4;1,2,3] 
B=[13,2,3;3,4,5;2,6,8] 

dot(A,B)

Output:

A =

3   20  34
2   3   4
1   2   3


B =

13  2   3
3   4   5
2   6   8


ans =

47  64  146

Explanation:

  • 47, 64 and 146 are the dot product value of the first, second and third corresponding columns of the matrices A and B.

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *