Multivariable Calculus for Machine Learning
Vectors and Geometry
Going Beyond Single Numbers
In math, we often work with single numbers, called scalars. Your age is a scalar. The price of a coffee is a scalar. But what if you need to describe something with both a size and a direction? For that, we use vectors.
A vector is like a set of instructions. "Walk 3 miles north" is a vector. It has a magnitude (3 miles) and a direction (north). In machine learning and physics, vectors are used everywhere to represent things like forces, velocities, or even data points in a high-dimensional space.
We can represent vectors using coordinates. A vector in a 2D plane might be written as , meaning it points 3 units along the x-axis and 4 units up the y-axis. The numbers 3 and 4 are its components. In three dimensions, a vector would have three components, like .
Vector Operations
Just like with numbers, we can perform operations on vectors. The two most basic are addition and scalar multiplication.
Vector Addition: To add two vectors, you just add their corresponding components. If and , then .
Geometrically, this is like following one set of instructions and then another. If you walk 3 miles north (vector ) and then 4 miles east (vector ), your final position relative to your start is the sum of the two vectors. This is often called the "head-to-tail" rule.
Scalar Multiplication: This means multiplying a vector by a scalar (a single number). This scales the vector's length. If is a scalar and , then .
Multiplying a vector by 2 doubles its length but keeps its direction. Multiplying by -1 reverses its direction but keeps its length. Multiplying by 0.5 halves its length.
Multiplying Vectors
How do you multiply two vectors? It's not as straightforward as adding them. There are two main ways: the dot product and the cross product.
Dot Product
noun
An operation that takes two vectors and returns a single scalar number. It measures how much one vector points in the direction of another.
The dot product of vectors and is written as . You calculate it by multiplying corresponding components and summing the results.
For example, if and , their dot product is .
The result's sign tells you about the angle between the vectors. If it's positive, the angle is less than 90°. If it's negative, the angle is greater than 90°.
Most importantly, if the dot product is zero, the vectors are orthogonal (perpendicular). This is a vital property used constantly in machine learning and geometry.
Next is the cross product, which is only defined for vectors in 3D space.
Cross Product
noun
An operation on two 3D vectors that produces a third vector that is perpendicular to both of the original vectors.
The cross product of and , written , creates a new vector. The direction of this new vector is found using the "right-hand rule": if you point your index finger in the direction of and your middle finger in the direction of , your thumb points in the direction of .
The magnitude (length) of the resulting vector is equal to the area of the parallelogram formed by and .
Lines and Planes in Space
Vectors are perfect for describing lines and planes. A line in space can be defined by a point on the line and a direction vector that is parallel to the line.
The vector equation of a line is , where is a point on the line, is the direction vector, and is a scalar parameter. As varies, traces out every point on the line.
Planes work similarly, but they are defined by a point and a normal vector—a vector that is perpendicular (orthogonal) to the plane. The equation of a plane is derived from the dot product.
If is the normal vector and is a known point on the plane, then for any other point on the plane, the vector from to must be perpendicular to . This means their dot product is zero:
This expands to the standard equation of a plane: . Understanding this geometric relationship is key to working with planes in higher dimensions, a common task in data analysis and machine learning.
Let's check your understanding of these core vector concepts.
Which of the following quantities is best represented by a vector?
Given two vectors, \[\vec{a} = (1, 2)\] and \[\vec{b} = (3, 1)\], what is their sum, \[\vec{a} + \vec{b}\]?