Dot products are the vector version of multiplication. To calculate the dot
product of two vectors you multiply the components of the vectors, then
add the resulting products together. For example, if we have vectors
v \mathbf{v} v and w \mathbf{w} w , their dot product
would look like this.
v = [ v 1 v 2 v 3 ⋮ v n ] , w = [ w 1 w 2 w 3 ⋮ w n ]
\mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ \vdots \\ v_n \end{bmatrix},
\quad \mathbf{w} = \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ \vdots \\ w_n \end{bmatrix}
v = v 1 v 2 v 3 ⋮ v n , w = w 1 w 2 w 3 ⋮ w n
v ⋅ w = [ v 1 v 2 v 3 ⋮ v n ] ⋅ [ w 1 w 2 w 3 ⋮ w n ] = v 1 ⋅ w 1 + v 2 ⋅ w 2 + v 3 ⋅ w 3 + ⋯ + v n + w n
\begin{aligned}
\mathbf{v} \cdot \mathbf{w}
&= \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ \vdots \\ v_n \end{bmatrix}
\cdot \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ \vdots \\ w_n \end{bmatrix} \\
&= v_1 \cdot w_1 + v_2 \cdot w_2 + v_3 \cdot w_3 + \cdots + v_n + w_n
\end{aligned}
v ⋅ w = v 1 v 2 v 3 ⋮ v n ⋅ w 1 w 2 w 3 ⋮ w n = v 1 ⋅ w 1 + v 2 ⋅ w 2 + v 3 ⋅ w 3 + ⋯ + v n + w n v ⋅ w = [ v 1 v 2 v 3 ⋮ v n ] ⋅ [ w 1 w 2 w 3 ⋮ w n ] = v 1 ⋅ w 1 + v 2 ⋅ w 2 + v 3 ⋅ w 3 + ⋯ + v n + w n
\mathbf{v} \cdot \mathbf{w}
= \begin{bmatrix} v_1 \\ v_2 \\ v_3 \\ \vdots \\ v_n \end{bmatrix}
\cdot \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ \vdots \\ w_n \end{bmatrix}
= v_1 \cdot w_1 + v_2 \cdot w_2 + v_3 \cdot w_3 + \cdots + v_n + w_n
v ⋅ w = v 1 v 2 v 3 ⋮ v n ⋅ w 1 w 2 w 3 ⋮ w n = v 1 ⋅ w 1 + v 2 ⋅ w 2 + v 3 ⋅ w 3 + ⋯ + v n + w n
Let us try that out with some real numbers:
v = [ 1 7 0 ] , w = [ 3 3 1 ]
\mathbf{v} = \begin{bmatrix} 1 \\ 7 \\ 0 \end{bmatrix},
\quad \mathbf{w} = \begin{bmatrix} 3 \\ 3 \\ 1 \end{bmatrix}
v = 1 7 0 , w = 3 3 1
v ⋅ w = [ 1 7 0 ] ⋅ [ 3 3 1 ] = 1 ⋅ 3 + 7 ⋅ 3 + 0 ⋅ 1 = 3 + 21 + 0 = 24
\begin{aligned}
\mathbf{v} \cdot \mathbf{w}
&= \begin{bmatrix} 1 \\ 7 \\ 0 \end{bmatrix}
\cdot \begin{bmatrix} 3 \\ 3 \\ 1 \end{bmatrix} \\
&= 1 \cdot 3 + 7 \cdot 3 + 0 \cdot 1 \\
&= 3 + 21 + 0 \\
&= 24
\end{aligned}
v ⋅ w = 1 7 0 ⋅ 3 3 1 = 1 ⋅ 3 + 7 ⋅ 3 + 0 ⋅ 1 = 3 + 21 + 0 = 24
You can calculate the dot product of as many vectors as you like with as many
components as you like. For example, if we define a third vector, x \mathbf{x} x ,
we can calculate the dot product v ⋅ w ⋅ x \mathbf{v} \cdot \mathbf{w} \cdot \mathbf{x} v ⋅ w ⋅ x :
x = [ 9 6 2 ]
\mathbf{x} = \begin{bmatrix} 9 \\ 6 \\ 2 \end{bmatrix}
x = 9 6 2
v ⋅ w ⋅ x = [ 1 7 0 ] ⋅ [ 3 3 1 ] ⋅ [ 9 6 2 ] = 1 ⋅ 3 ⋅ 9 + 7 ⋅ 3 ⋅ 6 + 0 ⋅ 1 ⋅ 2 = 27 + 126 + 0 = 153
\begin{aligned}
\mathbf{v} \cdot \mathbf{w} \cdot \mathbf{x}
&= \begin{bmatrix} 1 \\ 7 \\ 0 \end{bmatrix}
\cdot \begin{bmatrix} 3 \\ 3 \\ 1 \end{bmatrix}
\cdot \begin{bmatrix} 9 \\ 6 \\ 2 \end{bmatrix} \\
&= 1 \cdot 3 \cdot 9 + 7 \cdot 3 \cdot 6 + 0 \cdot 1 \cdot 2 \\
&= 27 + 126 + 0 \\
&= 153
\end{aligned}
v ⋅ w ⋅ x = 1 7 0 ⋅ 3 3 1 ⋅ 9 6 2 = 1 ⋅ 3 ⋅ 9 + 7 ⋅ 3 ⋅ 6 + 0 ⋅ 1 ⋅ 2 = 27 + 126 + 0 = 153
A practical application of dot products is calculating the value of all the
shares in your portfolio. You could define a price vector, p \mathbf{p} p ,
which contains the current price of each share, and a quantity vector q \mathbf{q} q ,
which holds the number of shares you own. Calculating the dot product
p ⋅ q \mathbf{p} \cdot \mathbf{q} p ⋅ q will give us the portfolio value.
Company Price Quantity Nvidia $174.18 17 Microsoft $506.69 8 Apple $232.14 42 Amazon $229.00 51
We can turn these prices and quantities into two vectors:
p = [ 174.18 506.69 232.14 229.00 ] , q = [ 17 8 42 51 ]
\mathbf{p} = \begin{bmatrix} 174.18 \\ 506.69 \\ 232.14 \\ 229.00 \end{bmatrix},
\quad \mathbf{q} = \begin{bmatrix} 17 \\ 8 \\ 42 \\ 51 \end{bmatrix}
p = 174.18 506.69 232.14 229.00 , q = 17 8 42 51
The dot product p ⋅ q \mathbf{p} \cdot \mathbf{q} p ⋅ q will give us the total
portfolio value.
p ⋅ q = [ 174.18 506.69 232.14 229.00 ] ⋅ [ 17 8 42 51 ] = 174.18 ⋅ 17 + 506.69 ⋅ 8 + 232.14 ⋅ 42 + 229.00 ⋅ 51 = 2961.06 + 4053.52 + 9749.88 + 11679.00 = $ 28 , 443.46
\begin{aligned}
\mathbf{p} \cdot \mathbf{q}
&= \begin{bmatrix} 174.18 \\ 506.69 \\ 232.14 \\ 229.00 \end{bmatrix}
\cdot \begin{bmatrix} 17 \\ 8 \\ 42 \\ 51 \end{bmatrix} \\
&= 174.18 \cdot 17 + 506.69 \cdot 8 + 232.14 \cdot 42 + 229.00 \cdot 51 \\
&= 2961.06 + 4053.52 + 9749.88 + 11679.00 \\
&= \$28,443.46
\end{aligned}
p ⋅ q = 174.18 506.69 232.14 229.00 ⋅ 17 8 42 51 = 174.18 ⋅ 17 + 506.69 ⋅ 8 + 232.14 ⋅ 42 + 229.00 ⋅ 51 = 2961.06 + 4053.52 + 9749.88 + 11679.00 = $28 , 443.46
Problems
If you can solve these problems you have understood how to calculate the dot
product of vectors.
Calculate the dot product of v \mathbf{v} v and w \mathbf{w} w
if:
v = [ 2 5 1 ] , w = [ 1 3 9 ]
\mathbf{v} = \begin{bmatrix} 2 \\ 5 \\ 1 \end{bmatrix},
\quad \mathbf{w} = \begin{bmatrix} 1 \\ 3 \\ 9 \end{bmatrix}
v = 2 5 1 , w = 1 3 9
Calculate the total value of the portfolio below by calculating the dot product
of vectors of price and quantity.
Company Price Quantity Meta $738.70 68 Broadcom $297.39 41 Alphabet $212.91 90 Berkshire Hathaway $502.98 7
Solutions
To calculate the dot product we first multiply each element of the two vectors
together, then add up the results:
v ⋅ w = [ 2 5 1 ] ⋅ [ 1 3 9 ] = 2 ⋅ 1 + 5 ⋅ 3 + 1 ⋅ 9 = 26
\begin{aligned}
\mathbf{v} \cdot \mathbf{w}
&= \begin{bmatrix} 2 \\ 5 \\ 1 \end{bmatrix}
\cdot \begin{bmatrix} 1 \\ 3 \\ 9 \end{bmatrix} \\
&= 2 \cdot 1 + 5 \cdot 3 + 1 \cdot 9 \\
&= 26
\end{aligned}
v ⋅ w = 2 5 1 ⋅ 1 3 9 = 2 ⋅ 1 + 5 ⋅ 3 + 1 ⋅ 9 = 26 v ⋅ w = [ 2 5 1 ] ⋅ [ 1 3 9 ] = 2 ⋅ 1 + 5 ⋅ 3 + 1 ⋅ 9 = 26
\mathbf{v} \cdot \mathbf{w}
= \begin{bmatrix} 2 \\ 5 \\ 1 \end{bmatrix}
\cdot \begin{bmatrix} 1 \\ 3 \\ 9 \end{bmatrix}
= 2 \cdot 1 + 5 \cdot 3 + 1 \cdot 9
= 26
v ⋅ w = 2 5 1 ⋅ 1 3 9 = 2 ⋅ 1 + 5 ⋅ 3 + 1 ⋅ 9 = 26
To calculate the total portfolio value we can turn the prices and quantities
of share into vectors, then calculate their dot product:
p ⋅ q = [ 738.70 297.39 212.91 502.98 ] ⋅ [ 68 41 90 7 ] = 738.70 ⋅ 68 + 297.39 ⋅ 41 + 212.91 ⋅ 90 + 502.98 ⋅ 7 = 50231.60 + 12192.99 + 19161.90 + 3520.86 = $ 85 , 107.35
\begin{aligned}
\mathbf{p} \cdot \mathbf{q}
&= \begin{bmatrix} 738.70 \\ 297.39 \\ 212.91 \\ 502.98 \end{bmatrix}
\cdot \begin{bmatrix} 68 \\ 41 \\ 90 \\ 7 \end{bmatrix} \\
&= 738.70 \cdot 68 + 297.39 \cdot 41 + 212.91 \cdot 90 + 502.98 \cdot 7 \\
&= 50231.60 + 12192.99 + 19161.90 + 3520.86 \\
&= \$85,107.35
\end{aligned}
p ⋅ q = 738.70 297.39 212.91 502.98 ⋅ 68 41 90 7 = 738.70 ⋅ 68 + 297.39 ⋅ 41 + 212.91 ⋅ 90 + 502.98 ⋅ 7 = 50231.60 + 12192.99 + 19161.90 + 3520.86 = $85 , 107.35