Recall (dot product)
let a=[a1a2a3] , be is the same in R3.
Dot product of a⋅b=a1b1 a2b2 a3b3.
a⋅a=∣∣a∣∣2 so ∣∣a∣∣=a⋅a
Properties of dot products:
- a⋅b=b⋅a
- a⋅(b c)=ab ac
- (αa)⋅b=a⋅(αb),α∈R
Fact: a⋅b=∣∣a∣∣⋅∣∣b∣∣cosθ where θ is the angle between a and b.
Proof (law of cosine)
||\vec{b} - \vec{a}||^2 = ||a||^2 + ||b||^2 - 2 ||\vec{a}|| ||\vec{b}|| \cos \theta\\
(\vec{b} - \vec{a})(\vec{b} - \vec{a}) = \vec{a}\cdot\vec{a} + \vec{b}\cdot\vec{b} - 2 ||\vec{a}|| ||\vec{b}|| \cos \theta \end{aligned} $$
after reduction.. $$ \begin{aligned} -2\vec{a}\cdot\vec{b} = -2||\vec{a}|| ||\vec{b}|| \cos \theta\\ \vec{a}\cdot\vec{b} = ||\vec{a}|| \cdot ||\vec{b}|| \cos \theta \end{aligned} $$
Corrolary: $\vec{a} \perp \vec{b} \iff \vec{a} \cdot \vec{b} = 0$
Ex: Find the angle between u=[-1\\1\\2] and v[2\\1\\-1]
$\cos \theta = \frac{\vec{a} \cdot \vec{b}}{||\vec{a}|| \cdot ||\vec{b}||}$
dot product works out to:
-2 + 1 - 2 = -3
$||u|| = \sqrt{-1^2 ~~ 1^2 ~~ 2^2} = \sqrt{6}$ $||v|| = \sqrt{2^2+1^2+-1^2} = \sqrt{6}$
plug into $\cos\theta$
$\frac{-3}{\sqrt{6}^2} = \frac{-3}{6} = \frac{-1}{2}$