---
title: Vectors as arrows and as lists
heading: An arrow you can also write as a list of numbers
eyebrow: A7 · Lesson 1 · Vectors
xp: 40
---

::: hook
A force has a size and a direction. So does an electric field, and so does a phasor. All of them are vectors, and you can think of a vector in two ways: as an arrow you can draw, or as a short list of numbers you can compute with. Linear algebra is the art of moving between the two pictures, and it scales from two numbers to the thousands of node voltages in a chip.

::: play
- $\mathbf{v}$ and $\mathbf{w}$ are vectors in the plane, set by their components. The third arrow is $\mathbf{v} + \mathbf{w}$, drawn tip to tail; the fourth is $c\,\mathbf{v}$.
- Change $c$ through negative values. What does a negative multiple do to the arrow?
- Make $\mathbf{v}$ and $\mathbf{w}$ point at right angles. What is their dot product in the strip?
:::
:::

```sim plot
view: complex
range: 4
slider: vx = -3..3 step 0.5 = 2
slider: vy = -3..3 step 0.5 = 1
slider: wx = -3..3 step 0.5 = -1
slider: wy = -3..3 step 0.5 = 2
slider: c = -2..2 step 0.25 = 1.5
arrow: vx + j*vy | label: v
arrow: wx + j*wy | from: vx + j*vy | dashed | color: ch2
arrow: wx + j*wy | color: ch2 | label: w
arrow: (vx + wx) + j*(vy + wy) | color: ch3 | label: v + w
arrow: c*(vx + j*vy) | color: ch4 | label: cv
readout: v · w = vx*wx + vy*wy
readout: |v| = sqrt(vx^2 + vy^2)
```

::: predict
## $\mathbf{v} = (2, 1)$ and $\mathbf{w} = (-1, 2)$. What is the angle between them?

- [ ] 45°
- [x] 90°
- [ ] 180°
- [ ] 0°

::: reveal
90°. Their dot product is $2 \times (-1) + 1 \times 2 = 0$, and a zero dot product means perpendicular. The dot product is the quickest test for right angles, and in higher dimensions, where you can't draw the arrows, it's the only one.
:::
:::

::: nameit
## Vectors, components and the dot product

A vector in the plane is written as a column of its **components**, $\mathbf{v} = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix}$, or as $(v_1, v_2)$. In three dimensions it has three components, and nothing stops you from having $n$: a circuit with 50 nodes has a vector of 50 node voltages.

**Arithmetic works component by component:**

- **Adding** places arrows tip to tail: $\mathbf{v} + \mathbf{w} = (v_1 + w_1,\ v_2 + w_2)$.
- **Scaling** by a number $c$ stretches the arrow: $c\mathbf{v} = (cv_1, cv_2)$. A negative $c$ flips it.
- **Length:** $|\mathbf{v}| = \sqrt{v_1^2 + v_2^2 + \cdots}$, Pythagoras in any number of dimensions.

**The dot product** multiplies matching components and adds:

$$\mathbf{v}\cdot\mathbf{w} = v_1w_1 + v_2w_2 + \cdots = |\mathbf{v}|\,|\mathbf{w}|\cos\theta$$

where θ is the angle between them. So it measures how much two vectors point the same way: positive if the angle is under 90°, zero if they're perpendicular, negative if over. The **projection** of $\mathbf{v}$ onto the direction of $\mathbf{w}$ has length $\mathbf{v}\cdot\mathbf{w}/|\mathbf{w}|$.

**In EE.** The power in a resistor network is a dot product of the branch voltages with the branch currents; work is the dot product of force with displacement; and the average power of an AC load, $\tfrac12V_mI_m\cos\theta$, is a dot product of two phasors drawn as arrows.

**Linear combinations.** Every combination $a\mathbf{v} + b\mathbf{w}$ of two vectors that don't point along the same line reaches every point of the plane. Two such vectors form a **basis**: a pair of directions you can describe everything with.
:::

::: example
## Find the angle between $\mathbf{v} = (3, 4)$ and $\mathbf{w} = (4, 3)$.

::: solution
1. **Dot product.**
   $$\begin{aligned} \mathbf{v}\cdot\mathbf{w} &= 12 + 12 \\ &= 24 \end{aligned}$$
2. **Lengths.** Both vectors have length 5: $|\mathbf{v}| = |\mathbf{w}| = 5$.
3. **Cosine of the angle.**
   $$\begin{aligned} \cos\theta &= \frac{24}{25} \\ &= 0.96 \end{aligned}$$
   so $\theta = 16.3°$.

**Answer:** the angle between them is 16.3°.
:::
:::

::: example
## A force of $(3, 4)$ N moves an object by $(2, 0)$ m. How much work does it do?

::: solution
1. **Work is a dot product.** Take the dot product of force and displacement:
   $$\begin{aligned} W &= 3 \times 2 + 4 \times 0 \\ &= 6\ \text{J} \end{aligned}$$
2. **Which part counts.** Only the force's component along the motion counts; the 4 N pushing sideways does no work.

**Answer:** the force does 6 J of work.
:::
:::

::: example
## Split $\mathbf{v} = (2, 3, 6)$ into a part along $\mathbf{w} = (1, 2, 2)$ and a part perpendicular to it.

::: solution
1. **Dot product.**
   $$\begin{aligned} \mathbf{v}\cdot\mathbf{w} &= 2 + 6 + 12 \\ &= 20 \end{aligned}$$
2. **Component along $\mathbf{w}$.** With $|\mathbf{w}| = 3$:
   $$\begin{aligned} \frac{\mathbf{v}\cdot\mathbf{w}}{|\mathbf{w}|} &= \frac{20}{3} \\ &= 6.67 \end{aligned}$$
3. **Part along $\mathbf{w}$.**
   $$\begin{aligned} \frac{\mathbf{v}\cdot\mathbf{w}}{\mathbf{w}\cdot\mathbf{w}}\mathbf{w} &= \frac{20}{9}(1, 2, 2) \\ &= (2.22, 4.44, 4.44) \end{aligned}$$
4. **Perpendicular part.** The rest is
   $$\begin{aligned} &(2, 3, 6) - (2.22, 4.44, 4.44) \\ &= (-0.22, -1.44, 1.56) \end{aligned}$$
5. **Check.**
   $$\begin{aligned} &(-0.22)(1) + (-1.44)(2) \\ &\quad + (1.56)(2) = 0 \end{aligned}$$
   so the second part really is perpendicular.
6. **Where this split is used.** It's how a force is resolved along a ramp and across it, and how a signal is resolved into the part that matches a reference and the part that doesn't.

**Answer:** the part along $\mathbf{w}$ is $(2.22, 4.44, 4.44)$ and the perpendicular part is $(-0.22, -1.44, 1.56)$.
:::
:::

::: check
given: a = -5 | -3 | -1 | 1 | 3 | 5; b = 2 | 4; c = -5 | -3 | -1 | 1 | 3 | 5; d = 2 | 4
answer: a*c + b*d
tolerance: 0.001

## What is $(\given{a}, \given{b}) \cdot (\given{c}, \given{d})$?

::: right
Right. Multiply matching components and add: {answer}.
:::

::: misses
- [a*d + b*c] Multiply matching components: first with first, second with second.
- [(a + c)*(b + d)] The dot product multiplies, then adds.
- [any] Not yet. Compute $\given{a}\cdot\given{c} + \given{b}\cdot\given{d}$.
:::
:::

::: check
given: a = 1..9 int; b = 1..9 int; c = 1..9 int
answer: sqrt(a^2 + b^2 + c^2)
tolerance: 0.5%

## What is the length of $(\given{a}, \given{b}, \given{c})$?

::: right
Right. Pythagoras extends to three components: {answer}.
:::

::: misses
- [a + b + c] Lengths combine by Pythagoras: square, add, take the root.
- [a^2 + b^2 + c^2] That's the length squared.
- [any] Not yet. Use $\sqrt{a^2 + b^2 + c^2}$.
:::
:::

::: check
given: a = 1 | 3 | 5; b = 2 | 4; c = 2 | 4; d = 1 | 3 | 5
answer: acos((a*c + b*d)/(sqrt(a^2 + b^2)*sqrt(c^2 + d^2)))*180/pi
unit: °
tolerance: 0.5%

## What is the angle between $(\given{a}, \given{b})$ and $(\given{c}, \given{d})$, in degrees?

::: right
Right. $\cos\theta = \mathbf{v}\cdot\mathbf{w}/(|\mathbf{v}||\mathbf{w}|)$, giving {answer}.
:::

::: misses
- [any] Not yet. Divide the dot product by both lengths, then take $\cos^{-1}$.
:::
:::

::: check
kind: choice

## Two vectors have a dot product of −6. What can you say about the angle between them?

- [ ] It's less than 90°
- [ ] It's exactly 90°
- [x] It's more than 90°
- [ ] Nothing

::: right
Right. $\cos\theta$ has the sign of the dot product, and it's negative for angles between 90° and 180°.
:::

::: misses
- [1] A positive dot product would mean under 90°.
- [2] Perpendicular vectors have a dot product of 0.
- [4] The sign tells you which side of 90° the angle is on.
:::
:::

::: check
kind: parts
given: a = 2 | 3 | 5; b = 1 | 4

## Take $\mathbf{v} = (\given{a}, 1, 2)$ and $\mathbf{w} = (1, \given{b}, 2)$.

::: part
answer: a + b + 4
tolerance: 0.5%

### What is $\mathbf{v}\cdot\mathbf{w}$?

::: misses
- [any] Multiply matching entries and add.
:::
:::

::: part
answer: sqrt(a^2 + 5)
tolerance: 0.5%

### What is $|\mathbf{v}|$?

::: misses
- [a + 3] Square the entries before adding, then take the square root.
- [any] $\sqrt{a^2 + 1^2 + 2^2}$.
:::
:::
:::

::: check
kind: derivation
vars: x = 0.5..5, y = 0.5..5

## Find the angle between $(x, y)$ and $(1, 0)$.

::: step
answer: x

### What is the dot product?
:::

::: step
answer: x/sqrt(x^2 + y^2)

### Divide by both lengths. What is $\cos\theta$?
:::

::: right
Right. $\cos\theta = \frac{x}{\sqrt{x^2 + y^2}}$: the angle any vector makes with the $x$ axis.
:::
:::

::: explain
## Why does a zero dot product mean two vectors are perpendicular?

::: model
The dot product equals the product of the two lengths times the cosine of the angle between them. If neither vector is zero, the lengths are positive, so the dot product can only be zero if the cosine is zero, which happens at exactly 90°. Geometrically, the dot product measures how much of one vector lies along the other, and a perpendicular vector has no part along it at all.
:::
:::

::: practice

::: check
given: a = -9 | -7 | -4 | -2 | 3 | 5 | 8; b = -9..9 int; c = 2..5 int
answer: c*a
tolerance: 0.001

## What is the first component of $\given{c}\,(\given{a}, \given{b})$?

::: misses
- [a] Multiply by {c}.
- [any] Scale each component by {c}.
:::
:::

::: check
given: a = 1..9 int; b = 1..9 int; c = 1..9 int; d = 1..9 int
answer: (a*c + b*d)/sqrt(c^2 + d^2)
tolerance: 0.5%

## What is the length of the projection of $(\given{a}, \given{b})$ onto the direction of $(\given{c}, \given{d})$?

::: misses
- [a*c + b*d] Divide by the length of the second vector.
- [any] $\mathbf{v}\cdot\mathbf{w}/|\mathbf{w}|$.
:::
:::

::: check
given: a = 1..9 int; b = 1..9 int
answer: -a/b
tolerance: 0.5%

## A vector $(\given{a}, \given{b})$ is perpendicular to $(1, y)$. What is $y$?

::: misses
- [a/b] The dot product $\given{a} + \given{b}y$ must be zero, which needs a negative y.
- [any] Set $\given{a}\cdot 1 + \given{b}\cdot y = 0$ and solve.
:::
:::
:::
