Number Representations & States

"how numbers are stored and used in computers"

Vector Dot Product

The dot product of two vectors is a scalar value that can be computed from their components. If and are two vectors, their dot product is given by:

In JavaScript, the dot product can be computed using the dotProduct function:

code.js
1function dotProduct(u, v) { 2 return u.reduce((sum, value, index) => sum + value * v[index], 0); 3}

This function takes two vectors (arrays) and returns their dot product as a number. For example:

code.js
1const u = [1, 2, 3]; 2const v = [4, 5, 6]; 3 4const dotProd = dotProduct(u, v); 5console.log(dotProd); // Output: 32

Properties of the Dot Product

The dot product has several important properties:

  1. Commutative Property:
  2. Distributive Property:
  3. Scalar Multiplication:

These properties make the dot product a useful tool in various applications, including physics, engineering, and computer graphics.