No history yet

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 v=(3,4)\vec{v} = (3, 4), 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 (x,y,z)(x, y, z).

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 a=(a1,a2)\vec{a} = (a_1, a_2) and b=(b1,b2)\vec{b} = (b_1, b_2), then a+b=(a1+b1,a2+b2)\vec{a} + \vec{b} = (a_1 + b_1, a_2 + b_2).

Geometrically, this is like following one set of instructions and then another. If you walk 3 miles north (vector a\vec{a}) and then 4 miles east (vector b\vec{b}), 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 cc is a scalar and v=(v1,v2)\vec{v} = (v_1, v_2), then cv=(cv1,cv2)c\vec{v} = (cv_1, cv_2).

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 a\vec{a} and b\vec{b} is written as ab\vec{a} \cdot \vec{b}. You calculate it by multiplying corresponding components and summing the results.

ab=a1b1+a2b2++anbn\vec{a} \cdot \vec{b} = a_1 b_1 + a_2 b_2 + \dots + a_n b_n

For example, if a=(1,2,3)\vec{a} = (1, 2, 3) and b=(4,5,6)\vec{b} = (4, -5, 6), their dot product is (1)(4)+(2)(5)+(3)(6)=410+18=12(1)(4) + (2)(-5) + (3)(6) = 4 - 10 + 18 = 12.

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 a\vec{a} and b\vec{b}, written a×b\vec{a} \times \vec{b}, 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 a\vec{a} and your middle finger in the direction of b\vec{b}, your thumb points in the direction of a×b\vec{a} \times \vec{b}.

The magnitude (length) of the resulting vector is equal to the area of the parallelogram formed by a\vec{a} and b\vec{b}.

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 r(t)=p+td\vec{r}(t) = \vec{p} + t\vec{d}, where p\vec{p} is a point on the line, d\vec{d} is the direction vector, and tt is a scalar parameter. As tt varies, r(t)\vec{r}(t) 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 n=(A,B,C)\vec{n} = (A, B, C) is the normal vector and p0=(x0,y0,z0)\vec{p_0} = (x_0, y_0, z_0) is a known point on the plane, then for any other point p=(x,y,z)\vec{p} = (x, y, z) on the plane, the vector from p0\vec{p_0} to p\vec{p} must be perpendicular to n\vec{n}. This means their dot product is zero:

n(pp0)=0\vec{n} \cdot (\vec{p} - \vec{p_0}) = 0

This expands to the standard equation of a plane: A(xx0)+B(yy0)+C(zz0)=0A(x-x_0) + B(y-y_0) + C(z-z_0) = 0. 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.

Quiz Questions 1/6

Which of the following quantities is best represented by a vector?

Quiz Questions 2/6

Given two vectors, \[\vec{a} = (1, 2)\] and \[\vec{b} = (3, 1)\], what is their sum, \[\vec{a} + \vec{b}\]?