Skip to content
DoingCamp CS

Make it comfy

Lesson style

Quick mode shows the key picture, a summary and the practice. Good for a refresher.

Theme
Font

Both fonts are designed to be easy to read. Some readers with dyslexia prefer Lexend.

Text size
Spacing
Animations

Lesson 1 of 20 · about 14 min

Vectors: arrows and lists

A vector is two things at once, an arrow you can draw and a list of numbers a computer can store. You'll drag arrows around a grid, add them tip to tail, stretch them, and measure them, then use them to work out where a plane really goes when the wind pushes it sideways.

🧭 What you need first: Functions

The story

A small plane points due east and flies through the air at 200 km/h. But the air itself is moving: a wind is blowing toward the north at 50 km/h. Where does the plane actually go?

Not east. Each hour, the plane moves 200 km east through the air, and the air carries it 50 km north. Over the ground, it slides off at an angle. Pilots have to work this out before every flight, and they draw it as a triangle of arrows, the wind triangle: the plane’s arrow, plus the wind’s arrow, gives the arrow of where you really go.

Those arrows are vectors, and they’re the starting point of linear algebra, the math that runs 3D games, search engines, image compression and machine learning. This course is going to be all about moving arrows around. First, let’s get to know a single arrow.

Another way: treasure-map directions

“From the old tree, walk 3 paces east and 2 paces north.” That instruction is a vector, (3, 2). It doesn’t matter where the tree is; the instruction is the same journey from any starting point. A vector is a move, not a place.

Play with it

Drag the arrows

Before you start dragging, guess: if v goes 2 right and 1 up, and w goes 1 right and 3 up, where do you end up if you walk v and then w?

v = (2, 1) and w = (1, 3). Where does walking v, then w, take you?

🎯 1/3: Drag v so that it points to (3, 2), the ★.

Drag the tips of v (blue) and w (orange). The dashed copy of w starts where v ends; the purple arrow goes straight to where you end up.

v + wwv

v = (2, 1), w = (1, 3), v + w = (3, 4)

Length of v: √(2² + 1²) = 2.24

Now stretch an arrow. Predict first: what does multiplying by −1 do?

🎯 1/3: Slide c so that c × v points to the ★ at (4, 2).

Drag the tip of v and slide the number c. The purple arrow is c × v: every component multiplied by c.

1vv

v = (2, 1), 1 × v = (2, 1)

Scaling never changes the line an arrow sits on. It stretches the arrow (c bigger than 1), shrinks it (c between 0 and 1), or flips it to point the other way (c negative).

Name it

The real words

  • A Vector in the plane is a pair of numbers v=(v1,v2)v = (v_1, v_2), its components. Drawn as an arrow, it starts at the origin (0,0)(0, 0) and ends at the point (v1,v2)(v_1, v_2). Mathematicians often write it as a column:

    v=[32]v = \begin{bmatrix} 3 \\ 2 \end{bmatrix}
  • Adding and scaling vectors:

    • Vector addition adds matching components. In the picture, put the second arrow’s tail on the first arrow’s tip:

      [21]+[13]=[34]\begin{bmatrix} 2 \\ 1 \end{bmatrix} + \begin{bmatrix} 1 \\ 3 \end{bmatrix} = \begin{bmatrix} 3 \\ 4 \end{bmatrix}
    • Scalar multiplication multiplies every component by one ordinary number, a scalar. −1⋅v-1 \cdot v flips vv; 0⋅v0 \cdot v is the zero vector (0,0)(0, 0).

    • Subtraction is adding a flipped arrow: w−v=w+(−1)vw - v = w + (-1)v, the arrow from vv‘s tip to ww‘s tip.

  • The length (or norm) comes from Pythagoras, since the components are the two short sides of a right triangle:

    ∣v∣=v12+v22|v| = \sqrt{v_1^2 + v_2^2}

    For (3,4)(3, 4): 9+16=5\sqrt{9 + 16} = 5.

  • Everything works the same with more components. A vector in 3D is (x,y,z)(x, y, z); a vector can have 1,000 components, which you can’t draw, but you add, scale and measure it exactly the same way.

Build it

Vectors in code

A vector is a Python list. Write add(v, w) (component by component, any number of components), scale(c, v) and length(v) (square root of the sum of squared components).

Challenge

The wind triangle

Back to the plane. Use xx for east and yy for north. The plane’s velocity through the air is air = [200, 0], and the wind is wind = [0, 50]. The velocity over the ground is their sum.

Write ground_velocity(air, wind) (their sum) and ground_speed(air, wind) (the length of that sum). Then where_after(air, wind, hours): the position after flying that long from (0, 0), which is hours × ground velocity.

To fly truly east, a pilot points the nose a little into the wind, so that the wind’s push and the plane’s sideways lean cancel out. Finding that heading is a vector problem too: you choose the air vector so that air + wind points where you want to go.

Remember it

v = (1, −2). What is 3v + (0, 5)?

Got it?

Finish the lesson to color it in on your map and collect its concept cards.

Did this lesson click?