DEV Community

Leandros Georgiou
Leandros Georgiou

Posted on

Linear algebra explained simply: how to calculate the dot product

The dot product works by taking two vectors of the same dimension and returning a single value.

For example,
Let's say we want to find the dot product of vectors [1, 2, 3] and [4, 5, 6]:

Step 1 - Multiply the numbers in matching positions:

1 * 4 = 4
2 * 5 = 10
3 * 6 = 18

Step 2 - Add up the results

4 + 10 + 18 = 32

Therefore [1, 2, 3]⸳[4, 5, 6] = 32

Let's look at another example. Let's say we wanted to find the dot product of vectors [8, 7] and [5, 2]:

Step 1 - Multiply the numbers in matching positions:

8 * 5 = 40
7 * 2 = 14

Step 2 - Add up the results

40 + 14 = 54

Therefore [8, 7]⸳[5, 2] = 54

Top comments (0)