Mascot image.
#EECS#Math#Vectors#Python

Why vectors show up so early

EECS gets abstract fast.

The reason vectors appear everywhere is that they let us encode many quantities at once: position, velocity, features of a data point, coefficients of a polynomial, even probabilities in a finite system.

The mathematical object

v=[21]v = \begin{bmatrix} 2 \\ -1 \end{bmatrix}

can be read as a point, an arrow, or just an ordered pair of numbers, depending on context.

Linear combinations

If

u=[10],w=[01],u = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, \qquad w = \begin{bmatrix} 0 \\ 1 \end{bmatrix},

then every vector of the form

au+bwau + bw

is a linear combination of uu and ww.

In the standard basis,

[32]=3[10]2[01].\begin{bmatrix} 3 \\ -2 \end{bmatrix} = 3\begin{bmatrix} 1 \\ 0 \end{bmatrix} - 2\begin{bmatrix} 0 \\ 1 \end{bmatrix}.

That sounds formal, but it is really just a recipe for building one object from simpler building blocks.

A Python representation

For a first pass, a vector can just be a tuple.

u = (1, 0)
w = (0, 1)

def add(a, b):
    return (a[0] + b[0], a[1] + b[1])

def scale(c, v):
    return (c * v[0], c * v[1])

v = add(scale(3, u), scale(-2, w))
print(v)  # (3, -2)

The code is tiny, but the conceptual point is big:

  • a vector is stored as data,
  • addition and scalar multiplication become operations,
  • mathematics becomes executable.

A tiny graph

This is the sort of thing I mean by “notes on the website” instead of only shipping files away as PDFs.

For the quadratic

f(x)=x24x+3=(x1)(x3),f(x) = x^2 - 4x + 3 = (x-1)(x-3),

you can already read off two roots:

x=1,x=3.x = 1, \qquad x = 3.

That kind of quick visual feedback is useful even in a theory-heavy course.

Recitation prompts

  1. Write a function that computes the dot product of two vectors in R2\mathbb{R}^2.
  2. Verify in code that uv=vuu \cdot v = v \cdot u for several examples.
  3. Pick two vectors and decide whether one is a scalar multiple of the other.

Homework direction

Try to answer this in both math language and code language:

If

v=[xy],v = \begin{bmatrix} x \\ y \end{bmatrix},

what does it mean for vv to lie on the line y=2xy = 2x?

In coordinates, the condition is

y=2x.y = 2x.

In code, it becomes a Boolean test.

def on_line(v):
    x, y = v
    return y == 2 * x

That translation from geometry to algebra to code is basically the entire spirit of the course.

If the notes keep that translation visible, the course page is doing its job.