# Vector Dot Product

Posted by Jeff on Sep 8, 2009 in Calculus, Electromagnetic Theory, Math, MATLAB, Physics, Statics |

### Vector dot product rules

Another simple review of the vector dot product, for those of you that have forgotten.  The operation that involves multiplying two vectors together can be done in a few ways.  The first operation is called either the scalar product or the dot product.  One of the well known definitions looks like this:

RULE 1: $A \cdot B \equiv |A||B|cos(\Theta)$

This is a scalar product that is equal to the two magnitudes multiplied together and multiplied by the cosine of the angle between them.  If  the two vectors are perpendicular to each other then the angle between them is 90 degrees, which will make the dot product equal zero.  This is an equivalent equation.

RULE 2: $A \cdot B \equiv A_{x}B_{x} + A_{y}B_{y} + A_{z}B_{z}$

When you finish your dot product, you should have a number, not a directional vector.  So if you get something like this you did something wrong: $3 u_{x} + 2 u_{y} - 5 u_{z}$.  If you ended up with $A \cdot B = 35$ (any #) then you don’t have to completely rule out your answer.

### Practice vectors

A few vectors to practice with:

$A = 2 u_{x} - 3 u_{y} + 5 u_{z}$

$B = u_{x} - 2 u_{y} + 2 u_{z}$

$|A| = \sqrt{(2)^{2} + (-3)^{2} + (5)^{2}} = \sqrt{38}$

$|B| = \sqrt{(1)^{2} + (-2)^{2} + (2)^{2}} = 3$

$A \cdot B = (2)(1) + (-3)(-2) + (5)(2) = 18$

Okay, now we have found our dot product by applying RULE 2 above.  We can use this value along with our individual vector magnitudes to apply RULE 1 and obtain the angle $\Theta$.

$\Theta = \arccos(\frac{A \cdot B}{|A||B|}) = 18.26 \cdot$

We can calculate the projection of the vector A onto the vector B by this relationship:

$proj_{B} A = \frac{A \cdot B}{|B|}$

Note that this is a scalar quantity, and that we can also define the projection of B onto vector A in a similar fashion:

$proj_{A} B = \frac{A \cdot B}{|A|}$

### Performing a vector dot product in MATLAB

Perform a dot product in MATLAB like so:

>>A = [ 1 2 3];

>>B = [2 3 4];

>>dot(A,B)

Enjoy