AI & ML — LAB
Vectors Lab
Set two vectors and watch every core vector operation update live — addition, subtraction, scalar multiplication, the dot product and the angle it implies, magnitude and unit vectors, and projection. This is the same math covered in Vectors & Dot Products, built as a free-form workspace instead of a fixed example.
How to Use This Lab
- Pick an operation from the buttons above the canvas — the visual and the worked formula below it update immediately.
- In the 2D Lab, drag the tip of vector A (blue) or B (pink) directly on the grid, or type exact values into the number boxes.
- In the 3D Lab, set x/y/z with the number boxes, then drag on the canvas to rotate the view and scroll to zoom.
- Some operations (scalar multiplication, magnitude) only use vector A — vector B is hidden for those since it isn’t part of the calculation.
The Lab
What Each Operation Means
Addition & Subtraction
A + B is found by walking A, then walking B from wherever A left off. A − B is the same as A + (−B) — walking A, then walking B’s exact opposite direction.
Scalar Multiplication
Multiplying a vector by a number k stretches or shrinks it by that factor, keeping its direction the same if k is positive, or flipping it if k is negative.
Dot Product & Angle
A · B multiplies matching components and adds them up. Because A · B = |A||B|cos θ, rearranging gives the angle θ between the two vectors directly from their components — no protractor needed.
Magnitude & Unit Vector
|A| is the length of A, found with the Pythagorean theorem extended to as many dimensions as A has. Dividing A by its own magnitude produces a unit vector — same direction, length exactly 1.
Projection
Projecting A onto B answers “how much of A points in B’s direction?” — geometrically, it’s the shadow A would cast onto the line through B if light fell perpendicular to that line.
Want the full explanation behind these formulas — including why the dot product measures similarity between embeddings, and how it powers a transformer’s attention mechanism? Read Vectors & Dot Products →