← Back to calculus 3

Dot Product

Dot product in 2D and 3D

For vectors

a=(a1,a2,a3),b=(b1,b2,b3),\vec{a} = (a_1, a_2, a_3), \quad \vec{b} = (b_1, b_2, b_3),

the dot product in 3D is

ab=a1b1+a2b2+a3b3.\vec{a} \cdot \vec{b} = a_1b_1 + a_2b_2 + a_3b_3.

In 2D, if

a=(a1,a2),b=(b1,b2),\vec{a} = (a_1, a_2), \quad \vec{b} = (b_1, b_2),

then

ab=a1b1+a2b2.\vec{a} \cdot \vec{b} = a_1b_1 + a_2b_2.

Example in 3D:

(2,1,3)(4,5,2)=24+(1)5+3(2)=3.(2,-1,3)\cdot(4,5,-2) = 2\cdot 4 + (-1)\cdot 5 + 3\cdot(-2) = -3.

Compute

(3,4)(2,5).(3,-4)\cdot(2,5).

Answer:

32+(4)5=620=14.3\cdot 2 + (-4)\cdot 5 = 6 - 20 = -14.

Compute

(1,2,1)(4,3,5).(1,2,-1)\cdot(4,-3,5).

Answer:

14+2(3)+(1)5=465=7.1\cdot 4 + 2\cdot(-3) + (-1)\cdot 5 = 4 - 6 - 5 = -7.

If

(x,2,1)(3,1,4)=9,(x,2,1)\cdot(3,-1,4)=9,

find xx.

Answer:

3x+2(1)+14=93x+2=9x=73.3x + 2(-1) + 1\cdot4 = 9 \Rightarrow 3x + 2 = 9 \Rightarrow x = \frac{7}{3}.

Arithmetic properties of dot product

For vectors a,b,c\vec{a},\vec{b},\vec{c} and scalar kk, the dot product satisfies:

  1. Commutative law
ab=ba\vec{a}\cdot\vec{b} = \vec{b}\cdot\vec{a}
  1. Distributive over addition
a(b+c)=ab+ac\vec{a}\cdot(\vec{b}+\vec{c}) = \vec{a}\cdot\vec{b} + \vec{a}\cdot\vec{c}
  1. Distributive in the first slot
(a+b)c=ac+bc(\vec{a}+\vec{b})\cdot\vec{c} = \vec{a}\cdot\vec{c} + \vec{b}\cdot\vec{c}
  1. Scalar multiplication compatibility
(ka)b=k(ab)=a(kb)(k\vec{a})\cdot\vec{b} = k(\vec{a}\cdot\vec{b}) = \vec{a}\cdot(k\vec{b})
  1. Zero vector property
a0=0,0a=0\vec{a}\cdot\vec{0}=0, \quad \vec{0}\cdot\vec{a}=0
  1. Self-dot gives squared magnitude
aa=a20\vec{a}\cdot\vec{a} = \|\vec{a}\|^2 \ge 0

These can be summarized as: dot product is symmetric and bilinear.

Given

ab=7,ac=2,\vec{a}\cdot\vec{b}=7,\quad \vec{a}\cdot\vec{c}=-2,

find

a(b+c).\vec{a}\cdot(\vec{b}+\vec{c}).

Answer:

a(b+c)=7+(2)=5.\vec{a}\cdot(\vec{b}+\vec{c}) = 7 + (-2) = 5.

If uv=3\vec{u}\cdot\vec{v}=-3, compute

(4u)(2v).(4\vec{u})\cdot(-2\vec{v}).

Answer:

(4u)(2v)=8(uv)=8(3)=24.(4\vec{u})\cdot(-2\vec{v}) = -8(\vec{u}\cdot\vec{v}) = -8(-3)=24.

If

ww=49,\vec{w}\cdot\vec{w}=49,

what is w\|\vec{w}\|?

Answer:

w=7.\|\vec{w}\|=7.

The angle theorem for dot product

Theorem. For nonzero vectors a,b\vec{a},\vec{b} with angle θ\theta between them,

ab=abcosθ.\vec{a}\cdot\vec{b} = \|\vec{a}\|\,\|\vec{b}\|\cos\theta.

Proof (using the law of cosines)

Consider the triangle formed by a\vec{a}, b\vec{b}, and ab\vec{a}-\vec{b}. By law of cosines,

ab2=a2+b22abcosθ.\|\vec{a}-\vec{b}\|^2 = \|\vec{a}\|^2 + \|\vec{b}\|^2 - 2\|\vec{a}\|\|\vec{b}\|\cos\theta.

On the other hand,

ab2=(ab)(ab)=aa2ab+bb=a2+b22ab.\|\vec{a}-\vec{b}\|^2 = (\vec{a}-\vec{b})\cdot(\vec{a}-\vec{b}) = \vec{a}\cdot\vec{a} - 2\vec{a}\cdot\vec{b} + \vec{b}\cdot\vec{b} = \|\vec{a}\|^2 + \|\vec{b}\|^2 - 2\vec{a}\cdot\vec{b}.

Compare the two expressions for ab2\|\vec{a}-\vec{b}\|^2:

a2+b22ab=a2+b22abcosθ.\|\vec{a}\|^2 + \|\vec{b}\|^2 - 2\vec{a}\cdot\vec{b} = \|\vec{a}\|^2 + \|\vec{b}\|^2 - 2\|\vec{a}\|\|\vec{b}\|\cos\theta.

Therefore,

ab=abcosθ.\vec{a}\cdot\vec{b}=\|\vec{a}\|\|\vec{b}\|\cos\theta.

In this graph, O=(0,0)O=(0,0), A=aA=\vec{a}, and B=bB=\vec{b}. The side ABAB is exactly ab\vec{a}-\vec{b}, so the triangle makes the law-of-cosines identity visible.

Triangle proof view: why |a-b|^2 = |a|^2 + |b|^2 - 2|a||b|cos(theta)

a⃗ = (4.00, 1.00)b⃗ = (2.00, 3.00)a⃗ · b⃗ = 11.000θ = 42.3°

Drag the coloured dots at the arrow tips to move each vector.

-8-7-6-5-4-3-2-112345678-6-5-4-3-2-1123456a⃗−b⃗θa⃗b⃗O

If

a=(1,2),b=(2,1),\vec{a}=(1,2),\quad \vec{b}=(2,1),

find the angle between them.

Answer:

ab=4,a=b=5.\vec{a}\cdot\vec{b}=4, \quad \|\vec{a}\|=\|\vec{b}\|=\sqrt{5}.

So

cosθ=45,heta=cos1(45)36.87.\cos\theta = \frac{4}{5}, \quad heta=\cos^{-1}\left(\frac{4}{5}\right)\approx 36.87^\circ.

Determine whether

u=(3,1,2),v=(1,5,1)\vec{u}=(3,-1,2),\quad \vec{v}=(1,5,1)

are perpendicular.

Answer:

uv=31+(1)5+21=0.\vec{u}\cdot\vec{v} = 3\cdot1 + (-1)\cdot5 + 2\cdot1 = 0.

Hence cosθ=0\cos\theta=0, so θ=90\theta=90^\circ and they are perpendicular.

Find kk so that

(k,1) is perpendicular to (2,6).(k,1)\ \text{is perpendicular to}\ (2,-6).

Answer:

Perpendicular means dot product =0=0:

2k+1(6)=02k6=0k=3.2k + 1\cdot(-6)=0 \Rightarrow 2k-6=0 \Rightarrow k=3.

Geometric meaning of dot product

The formula

ab=abcosθ\vec{a}\cdot\vec{b}=\|\vec{a}\|\|\vec{b}\|\cos\theta

gives several geometric interpretations:

  1. Angle information:
cosθ=abab\cos\theta = \frac{\vec{a}\cdot\vec{b}}{\|\vec{a}\|\|\vec{b}\|}
  1. Sign tells relative direction:

    • ab>0\vec{a}\cdot\vec{b}>0 means acute angle (0<θ<900^\circ<\theta<90^\circ)
    • ab=0\vec{a}\cdot\vec{b}=0 means right angle (θ=90\theta=90^\circ)
    • ab<0\vec{a}\cdot\vec{b}<0 means obtuse angle (90<θ<18090^\circ<\theta<180^\circ)
  2. Orthogonality test:

ab    ab=0\vec{a}\perp\vec{b} \iff \vec{a}\cdot\vec{b}=0
  1. Directional component / projection relation:
ab=b(scalar projection of a on b).\vec{a}\cdot\vec{b} = \|\vec{b}\|\,(\text{scalar projection of }\vec{a}\text{ on }\vec{b}).

Use this to explore acute/obtuse/perpendicular cases by changing a\vec{a} and b\vec{b}. The annotation shows cosθ\cos\theta and both sides of the identity.

Geometric meaning: angle sign and dot-product identity

a⃗ = (3.00, 2.00)b⃗ = (4.00, -1.00)a⃗ · b⃗ = 10.000θ = 47.7°

Drag the coloured dots at the arrow tips to move each vector.

-8-7-6-5-4-3-2-112345678-6-5-4-3-2-1123456a⃗−b⃗θa⃗b⃗O

Without finding the exact angle, classify the angle between

p=(2,1,1),q=(1,3,0).\vec{p}=(2,1,-1),\quad \vec{q}=(1,3,0).

Answer:

pq=21+13+(1)0=5>0.\vec{p}\cdot\vec{q}=2\cdot1+1\cdot3+(-1)\cdot0=5>0.

So the angle is acute.

Are

p=(1,2,3),q=(2,1,0)\vec{p}=(1,2,3),\quad \vec{q}=(2,-1,0)

orthogonal?

Answer:

pq=12+2(1)+30=0.\vec{p}\cdot\vec{q}=1\cdot2+2\cdot(-1)+3\cdot0=0.

Yes, they are orthogonal.

For

u=(1,0,1),v=(2,2,1),\vec{u}=(1,0,1),\quad \vec{v}=(2,2,1),

find cosθ\cos\theta.

Answer:

uv=3,u=2,v=3.\vec{u}\cdot\vec{v}=3, \quad \|\vec{u}\|=\sqrt{2}, \quad \|\vec{v}\|=3.

Thus

cosθ=332=12.\cos\theta=\frac{3}{3\sqrt{2}}=\frac{1}{\sqrt{2}}.

Scalar projection vs vector projection

Let a\vec{a} be projected onto a nonzero vector b\vec{b}.

Scalar projection (component)

The scalar projection of a\vec{a} onto b\vec{b} is

compba=abb.\operatorname{comp}_{\vec{b}}\vec{a} = \frac{\vec{a}\cdot\vec{b}}{\|\vec{b}\|}.

This is a number. It can be positive, negative, or zero.

Vector projection

The vector projection of a\vec{a} onto b\vec{b} is

projba=(abb2)b.\operatorname{proj}_{\vec{b}}\vec{a} = \left(\frac{\vec{a}\cdot\vec{b}}{\|\vec{b}\|^2}\right)\vec{b}.

This is a vector in the direction of b\vec{b} (or opposite if the coefficient is negative).

Relationship:

projba=(compba)bb.\operatorname{proj}_{\vec{b}}\vec{a} = \left(\operatorname{comp}_{\vec{b}}\vec{a}\right)\frac{\vec{b}}{\|\vec{b}\|}.

In the graph below, the purple vector is projba\operatorname{proj}_{\vec{b}}\vec{a} and the red dashed segment is the rejection aprojba\vec{a}-\operatorname{proj}_{\vec{b}}\vec{a}.

Projection view: scalar component vs projection vector

a⃗ = (5.00, 2.00)b⃗ = (3.00, 0.00)a⃗ · b⃗ = 15.000θ = 21.8°comp_b(a⃗) = 5.000proj_b(a⃗) = (5.00, 0.00)

Drag the coloured dots at the arrow tips to move each vector.

-8-7-6-5-4-3-2-112345678-6-5-4-3-2-1123456projθa⃗b⃗O

Let

a=(3,4),b=(1,0).\vec{a}=(3,4),\quad \vec{b}=(1,0).

Find compba\operatorname{comp}_{\vec{b}}\vec{a}.

Answer:

compba=abb=31=3.\operatorname{comp}_{\vec{b}}\vec{a} =\frac{\vec{a}\cdot\vec{b}}{\|\vec{b}\|} =\frac{3}{1}=3.

Let

a=(3,4),b=(1,0).\vec{a}=(3,4),\quad \vec{b}=(1,0).

Find projba\operatorname{proj}_{\vec{b}}\vec{a}.

Answer:

projba=(abb2)b=(31)(1,0)=(3,0).\operatorname{proj}_{\vec{b}}\vec{a} =\left(\frac{\vec{a}\cdot\vec{b}}{\|\vec{b}\|^2}\right)\vec{b} =\left(\frac{3}{1}\right)(1,0)=(3,0).

Let

a=(2,1),b=(4,0).\vec{a}=(2,1),\quad \vec{b}=(-4,0).

Find both compba\operatorname{comp}_{\vec{b}}\vec{a} and projba\operatorname{proj}_{\vec{b}}\vec{a}.

Answer:

ab=8,b=4,b2=16.\vec{a}\cdot\vec{b}= -8, \quad \|\vec{b}\|=4, \quad \|\vec{b}\|^2=16.

So

compba=84=2,\operatorname{comp}_{\vec{b}}\vec{a}=\frac{-8}{4}=-2,

and

projba=(816)(4,0)=(12)(4,0)=(2,0).\operatorname{proj}_{\vec{b}}\vec{a} =\left(\frac{-8}{16}\right)(-4,0) =\left(-\frac{1}{2}\right)(-4,0) =(2,0).

The scalar projection is a signed number (2-2), while the vector projection is an actual vector ((2,0)(2,0)).


Mixed practice on dot product

Given

u=(1,2,2),v=(2,1,0),\vec{u}=(1,-2,2),\quad \vec{v}=(2,1,0),

compute uv\vec{u}\cdot\vec{v} and decide whether the angle is acute, right, or obtuse.

Compute the dot product first, then use its sign.

uv=12+(2)1+20=0.\vec{u}\cdot\vec{v}=1\cdot2+(-2)\cdot1+2\cdot0=0.

So the vectors are orthogonal and the angle is right.

Find the angle between

a=(1,1,0),b=(1,0,1).\vec{a}=(1,1,0),\quad \vec{b}=(1,0,1).

Use cosθ=abab\cos\theta=\dfrac{\vec{a}\cdot\vec{b}}{\|\vec{a}\|\|\vec{b}\|}.

ab=1,a=2,b=2.\vec{a}\cdot\vec{b}=1, \quad \|\vec{a}\|=\sqrt{2}, \quad \|\vec{b}\|=\sqrt{2}.

Therefore

cosθ=12,θ=60.\cos\theta=\frac{1}{2},\quad \theta=60^\circ.

For

a=(4,2,0),b=(2,0,0),\vec{a}=(4,2,0),\quad \vec{b}=(2,0,0),

find both compba\operatorname{comp}_{\vec{b}}\vec{a} and projba\operatorname{proj}_{\vec{b}}\vec{a}.

Compute ab\vec{a}\cdot\vec{b}, then divide by b\|\vec{b}\| or b2\|\vec{b}\|^2 as needed.

ab=8,b=2,b2=4.\vec{a}\cdot\vec{b}=8, \quad \|\vec{b}\|=2, \quad \|\vec{b}\|^2=4.

So

compba=82=4,\operatorname{comp}_{\vec{b}}\vec{a}=\frac{8}{2}=4,

and

projba=(84)(2,0,0)=2(2,0,0)=(4,0,0).\operatorname{proj}_{\vec{b}}\vec{a} =\left(\frac{8}{4}\right)(2,0,0) =2(2,0,0)=(4,0,0).

Find all kk such that

(k,2,1)(3,k,6).(k,2,-1)\perp(3,k,6).

Perpendicular vectors have dot product zero.

(k,2,1)(3,k,6)=3k+2k6=0(k,2,-1)\cdot(3,k,6)=3k+2k-6=0

so

5k=6k=65.5k=6 \Rightarrow k=\frac{6}{5}.