Alex Loftus
← Back to the lesson

Functions, vectors, and the dot product

A weighted-sum function and a dot product package the same calculation in two forms.
A weighted-sum function and a dot product package the same calculation in two forms.

A vector can be an input to a function

A function is a rule that turns an input into an output. The input need not be one number. Suppose an input has two measurements, x1x_1 and x2x_2, and our rule triples the first and doubles the second:

f(x1,x2)=3x1+2x2.f(x_1,x_2)=3x_1+2x_2.

For the input (4,1)(4,1), the output is 3×4+2×1=143\times4+2\times1=14. Two numbers went in; one came out.

Store the rule as a vector

The numbers (3,2)(3,2) describe how strongly each input contributes. Pair them with the input, multiply corresponding entries, then add:

(3,2)⋅(4,1)=3×4+2×1=14.(3,2)\cdot(4,1)=3\times4+2\times1=14.

That operation is the dot product. The expression 3x1+2x23x_1+2x_2 and the expression (3,2)⋅(x1,x2)(3,2)\cdot(x_1,x_2) describe the same calculation.

For nn inputs, the pattern is unchanged:

w⋅x=∑i=1nwixi.w\cdot x=\sum_{i=1}^{n}w_i x_i.

The coefficients wiw_i are often called weights. A zero weight ignores an input; a negative weight subtracts its contribution.

The rule has a shape

The input (x1,x2)(x_1,x_2) lives in a plane. A graph showing the input and the output has three coordinates, (x1,x2,f(x1,x2))(x_1,x_2,f(x_1,x_2)). Drawing that graph in 3D does not make the input three-dimensional.

Because this rule only scales and adds, doubling the input doubles the output. Adding two inputs before applying the rule gives the same result as applying it separately and adding the outputs. This is what makes the rule linear.

Try a new input

What does the same rule return for (0,5)(0,5)?

Answer: 3×0+2×5=103\times0+2\times5=10. The first coordinate contributes nothing this time.