dot_product.md (2928B)
1 # Dot Product 2 3 The dot product is an operation that takes two vectors of the same dimension and 4 returns a single real number (a scalar), often written with a centered dot like 5 \(\mathbf{a} \cdot \mathbf{b}\). 6 7 ## Algebraic definition 8 9 For vectors in $$ \mathbb{R}^n $$ 10 11 $$ 12 \mathbf{a} = 13 \begin{pmatrix} 14 a_1\\ 15 a_2\\ 16 \vdots\\ 17 a_n 18 \end{pmatrix}, 19 \quad 20 \mathbf{b} = 21 \begin{pmatrix} 22 b_1\\ 23 b_2\\ 24 \vdots\\ 25 b_n 26 \end{pmatrix}, 27 $$ 28 29 their dot product is 30 31 $$ 32 33 \mathbf{a} \cdot \mathbf{b} = 34 35 a_1 b_1 + a_2 b_2 + \dots + a_n b_n. 36 37 $$ 38 39 Example in $$ \mathbb{R}^3 $$ 40 41 $$ 42 43 \begin{pmatrix} 1\\ 3\\ -5 \end{pmatrix} \cdot \begin{pmatrix} 4\\ -2\\ -1 44 \end{pmatrix} = 45 46 1\cdot 4 + 3\cdot(-2) + (-5)\cdot(-1) = 47 48 4 - 6 + 5 = 3. 49 50 $$ 51 52 ## Geometric definition 53 54 If $$ \mathbf{a}, \mathbf{b} \in \mathbb{R}^n $$ 55 56 and $$ \theta $$ 57 58 is the angle between them, then 59 60 $$ \mathbf{a} \cdot \mathbf{b} $$ 61 62 $$ \|\mathbf{a}\|\;\|\mathbf{b}\|\cos\theta, $$ 63 64 where $$ \|\mathbf{a}\| $$ 65 66 is the Euclidean length (norm) of $$ \mathbf{a} $$ 67 68 From this, you also get 69 70 $$ 71 \mathbf{a} \cdot \mathbf{a} = \|\mathbf{a}\|^2, 72 \quad 73 \|\mathbf{a}\| = \sqrt{\mathbf{a} \cdot \mathbf{a}}. 74 $$ 75 76 ## Basic calculation rules 77 78 Let $$ \mathbf{a}, \mathbf{b}, \mathbf{c} \in \mathbb{R}^n $$ 79 80 and $$ \lambda \in 81 \mathbb{R} $$ 82 83 Then: 84 85 - Commutativity: 86 87 $$ 88 \mathbf{a} \cdot \mathbf{b} = \mathbf{b} \cdot \mathbf{a}. 89 $$ 90 91 - Distributivity over addition: 92 93 $$ 94 \mathbf{a} \cdot (\mathbf{b} + \mathbf{c}) = 95 \mathbf{a} \cdot \mathbf{b} + \mathbf{a} \cdot \mathbf{c}. 96 $$ 97 98 - Homogeneity (scalar multiplication in one slot): 99 100 $$ 101 (\lambda \mathbf{a}) \cdot \mathbf{b} = 102 \lambda (\mathbf{a} \cdot \mathbf{b}), \quad \mathbf{a} \cdot (\lambda \mathbf{b}) = 103 \lambda (\mathbf{a} \cdot \mathbf{b}). 104 $$ 105 106 - Positivity: 107 108 $$ 109 \mathbf{a} \cdot \mathbf{a} \ge 0 110 \quad \text{and} \quad 111 \mathbf{a} \cdot \mathbf{a} = 0 \iff \mathbf{a} = \mathbf{0}. 112 $$ 113 114 ## Worked examples 115 116 1. Simple 2D example 117 118 Let 119 120 $$ 121 \mathbf{u} = 122 \begin{pmatrix} 123 2\\ 124 -1 125 \end{pmatrix}, 126 \quad 127 \mathbf{v} = 128 \begin{pmatrix} 129 3\\ 130 4 131 \end{pmatrix}. 132 $$ 133 134 Then 135 136 $$ \mathbf{u} \cdot \mathbf{v} 137 2\cdot 3 + (-1)\cdot 4 = 138 6 - 4 = 139 2. 140 $$ 141 142 2. 4D example 143 144 Let 145 146 $$ 147 \mathbf{x} = 148 \begin{pmatrix} 149 2\\ 150 0\\ 151 -3\\ 152 1 153 \end{pmatrix}, 154 \quad 155 \mathbf{y} = 156 \begin{pmatrix} 157 -1\\ 158 3\\ 159 1\\ 160 2 161 \end{pmatrix}. 162 $$ 163 164 Then 165 166 $$ 167 \mathbf{x} \cdot \mathbf{y} = 168 2(-1) + 0(3) + (-3)(1) + 1(2) = 169 -2 + 0 - 3 + 2 = 170 -3. 171 $$ 172 173 3. Using the geometric form to find an angle 174 175 Let 176 177 $$ 178 \mathbf{a} = 179 \begin{pmatrix} 180 1\\ 181 2 182 \end{pmatrix}, 183 \quad 184 \mathbf{b} = 185 \begin{pmatrix} 186 2\\ 187 1 188 \end{pmatrix}. 189 $$ 190 191 Compute 192 193 $$ 194 195 \mathbf{a} \cdot \mathbf{b} = 1\cdot 2 + 2\cdot 1 4, 196 197 $$ 198 199 $$ 200 201 \|\mathbf{a}\| = 202 203 \sqrt{1^2 + 2^2} = 204 205 \sqrt{5}, \quad \|\mathbf{b}\| = 206 207 \sqrt{2^2 + 1^2} = 208 209 \sqrt{5}. 210 211 $$ 212 213 So 214 215 $$ 216 217 \cos\theta = 218 219 \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{a}\|\,\|\mathbf{b}\|} = 220 221 \frac{4}{\sqrt{5}\sqrt{5}} = 222 223 \frac{4}{5}, 224 225 $$ 226 227 and hence 228 229 $$ 230 \theta = \arccos\!\left(\frac{4}{5}\right). 231 $$