Vector Operations

Beginner course · learn by doing

Vector operations, one move at a time.

You do not need to memorize the formulas first. Move the arrows, use the sliders, and watch what changes. Then read the short explanation underneath.

1. Move itDrag an orange point.

2. Tune itUse the sliders for small, precise changes.

3. Observe itWatch the black result and the numbers.

What is a vector?

A vector is an arrow that stores two things: direction and amount.

A single vector

Try it: drag the orange point, or move the x and y sliders below. Watch how the arrow changes direction and length.

Manual controls

Vector(3.0, 2.0)
Length3.61

The interactive could not load. Check your connection and reload.

The simple idea

The number x tells you how far to move sideways. The number y tells you how far to move up or down. Together they define the arrow.

\[\mathbf v=(x,y)\]

A vector is useful whenever something has both a size and a direction: velocity, force, wind, a direction to a target, and more.

Try: set x to 0. What direction can the vector point now?

Vector addition

Addition combines two effects that happen at the same time.

Drone + wind

Try it: drag either colored endpoint, or move the sliders below. Watch the black arrow show the combined motion.

Manual controls

Drone—
Wind—
Combined—

The interactive could not load. Check your connection and reload.

What is happening?

The drone moves, and the wind pushes it at the same time. The black arrow is where those two motions lead together.

Add x to x, and y to y:

\[\mathbf a+\mathbf b=(a_x+b_x,\;a_y+b_y)\]

Try: make the wind point almost opposite the drone. Notice how the black arrow gets shorter.

Vector subtraction

Subtraction tells you how one motion looks relative to another.

Two cars on the same road

Try it: change either car's speed. Watch the black arrow show how Car A moves from Car B's point of view.

Manual controls

A − B—
What B sees—

The interactive could not load. Check your connection and reload.

The simple idea

If both cars move at the same speed in the same direction, neither car pulls away from the other. Their relative velocity is zero.

\[\mathbf v_{A/B}=\mathbf v_A-\mathbf v_B\]

Try: give both cars exactly 90 km/h. Then increase only Car B.

Scalar multiplication

A scalar is just a normal number. Multiplying a vector by it changes the vector's size.

Change the throttle

Try it: drag the base vector or tune it with the sliders, then change k. Watch the black result stretch, shrink, or flip.

Manual controls

Original—
Result—

The interactive could not load. Check your connection and reload.

What k does

  • k bigger than 1 makes the vector longer.
  • k between 0 and 1 makes it shorter.
  • k = 0 removes the vector.
  • negative k flips the direction.
\[k\mathbf v=(kv_x,\;kv_y)\]

Try: set k to -1.

Magnitude

Magnitude means the length of a vector.

How fast is the boat?

Try it: drag the orange point, or use the x and y sliders. Watch the black arrow's length change.

Manual controls

x component—
y component—
Magnitude—

The interactive could not load. Check your connection and reload.

Why this formula?

The x and y parts make a right triangle. The vector is the diagonal, so we use the Pythagorean theorem.

\[\|\mathbf v\|=\sqrt{x^2+y^2}\]

Try: set x = 3 and y = 4. The length should become 5.

Normalization

Normalization keeps the direction but changes the vector's length to exactly 1.

Direction only

Try it: move the orange target, or use the x and y sliders. The black arrow keeps the same direction but always has length 1.

Manual controls

Original vector—
Unit vector—

The interactive could not load. Check your connection and reload.

Why do this?

Sometimes you only want a direction, not a distance. Dividing by the vector's own length makes its new length equal to 1.

\[\hat{\mathbf v}=\frac{\mathbf v}{\|\mathbf v\|}\]

Try: move the target far away, then very close. The black direction arrow stays the same length.

Dot product

The dot product tells you whether two vectors point mostly together, sideways, or opposite.

Are we moving toward the target?

Try it: drag either colored endpoint, or tune both vectors with the sliders. Watch the sign of the dot product.

Manual controls

Dot product—
Angle—
Meaning—

The interactive could not load. Check your connection and reload.

Read the sign first

  • positive: the vectors point mostly the same way.
  • zero: they are at 90°.
  • negative: they point mostly opposite ways.
\[\mathbf a\cdot\mathbf b=a_xb_x+a_yb_y\]

Try: make the two vectors perpendicular and aim for a dot product near 0.

Angle between vectors

The angle tells you how much one direction must turn to face another.

Turn toward the dock

Try it: drag the dock, or move its x and y sliders. Watch the turn angle change with it.

Manual controls

Turn angle—
Instruction—

The interactive could not load. Check your connection and reload.

What the angle means

0° means the directions match. 90° means sideways. 180° means exactly opposite.

\[\theta=\cos^{-1}\!\left(\frac{\mathbf a\cdot\mathbf b}{\|\mathbf a\|\,\|\mathbf b\|}\right)\]

Try: place the dock directly behind the boat and look for an angle near 180°.

Projection

Projection asks: “How much of this vector acts in that direction?”

Gravity along a hill

Try it: change the hill angle with the slider or type a value. Watch the orange part of gravity grow along the road.

Manual control

Hill angle22°
Gravity along hill—

The interactive could not load. Check your connection and reload.

The simple idea

Gravity points straight down, but only part of it pulls along the hill. That part is the projection.

\[g_{\parallel}=g\sin(\theta)\]

Try: set the hill to 0°. The force along the hill should become 0.

Put it together

A drone is trying to reach a package while wind pushes it off course.

Course correction

Your goal: drag the drone or wind vectors, or tune them with the sliders below. Make the black ground-velocity arrow point as closely as possible toward the package.

Manual controls

Alignment—
Ground speed—
Direction error—
Status—

The interactive could not load. Check your connection and reload.

What you are using

First, the wind and drone velocities add. Then we compare the result with the direction to the package.

\[\mathbf v_{ground}=\mathbf v_{drone}+\mathbf v_{wind}\]

If the alignment is close to 1 and the direction error is close to 0°, you are aimed at the package.

Change values freely. The point of the course is to build intuition by seeing the result move.
ModuleMachine Learning