Courses / Computer Science I
Algebra

Dot Product and Orthogonality

Computer Science I 284 words Free to read

Multiplying Vectors to Get a Number

The dot product takes two vectors and returns a single number (a scalar). For u=(u1,u2)u = (u_1, u_2) and v=(v1,v2)v = (v_1, v_2): uv=u1v1+u2v2.u \cdot v = u_1 v_1 + u_2 v_2. Multiply matching components and add. This simple operation encodes a surprising amount of geometry.

Its geometric meaning is the key: uv=uvcosθu \cdot v = \|u\|\,\|v\|\cos\theta, where θ\theta is the angle between the vectors. So the dot product measures how aligned two vectors are:

The orthogonality test is the most-used consequence: two nonzero vectors are perpendicular exactly when their dot product is zero. No angle computation needed — just check if uv=0u \cdot v = 0. This is how graphics code tests perpendicularity and how projections are computed.

The dot product also recovers length (uu=u2u \cdot u = \|u\|^2) and lets you find the angle between vectors via cosθ=uvuv\cos\theta = \frac{u \cdot v}{\|u\|\,\|v\|}. In machine learning, the closely related cosine similarity uses exactly this to measure how similar two feature vectors are — the backbone of search and recommendation.

Common pitfall: confusing the dot product (which returns a number) with scaling or componentwise multiplication that returns a vector, and forgetting that orthogonal means dot product zero. uvu \cdot v is a single scalar u1v1+u2v2u_1 v_1 + u_2 v_2, not a vector. And perpendicular vectors have uv=0u \cdot v = 0 — a positive or negative dot product means the angle is acute or obtuse, never a right angle.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

10practice questions
2interactive scenes
Start Computer Science I free

Algebra