Part I · Chapter 1

Basic Linear Algebra

Read ~20 min Prerequisites none Tools vector plane, matrix transformer, code cell Live

Everything in this book eventually comes down to multiplying a small list of numbers by a small grid of numbers. That's all a qubit state is, and that's all a gate is. The only thing quantum mechanics adds to ordinary linear algebra is that the numbers are allowed to be complex — the rules themselves don't change at all.

What a vector is, here

A vector is just an ordered list of numbers, written as a column:

v = [v₁, v₂, …, vₙ]ᵗ

For most of this chapter n = 2, because a single qubit's state will turn out to be a 2-entry vector. Everything below works identically for any size.

Adding vectors

Vector addition is component-by-component: add the first entries together, add the second entries together. Geometrically, this is the familiar "tip-to-tail" rule — slide the second arrow so its tail sits at the first arrow's tip, and the sum is the arrow from the very start to the very end.

Fig. 1.1 — drag either vectora + b
Blue is a, gray is b, the dashed line shows b moved to start at a's tip (tip-to-tail), and amber is the resulting sum a + b.

Scalar multiplication

Multiplying a vector by a single number k scales every entry by k: (kv)ᵢ = k·vᵢ. Geometrically that stretches (|k| > 1), shrinks (|k| < 1), or reverses (k < 0) the arrow without changing its direction otherwise. You'll see this as a special case of the next section — try setting the matrix below to [[k,0],[0,k]] and watch it scale your vector uniformly.

Matrices as transformations

A matrix is a grid of numbers that turns one vector into another. For a 2×2 matrix acting on a 2-entry vector, the rule is:

$$\begin{bmatrix}a&b\\c&d\end{bmatrix}\begin{bmatrix}v_1\\v_2\end{bmatrix}=\begin{bmatrix}av_1+bv_2\\cv_1+dv_2\end{bmatrix}$$

Each output entry is a weighted sum of the input entries — nothing more exotic than that. The widget below lets you edit the matrix directly and drag the vector, so you can watch exactly which matrices stretch, rotate, reflect, or swap a vector's direction.

Fig. 1.2 — edit the matrix, drag the vectorv → Mv
Blue is your input vector v, amber is the output Mv. "Swap (X-like)" is worth lingering on — it's the exact real-number shadow of the X gate from Ch. 3.

This is literally what a quantum gate does

Go back to Ch. 3's gate buttons for a moment: every one of them was a 2×2 matrix multiplying a 2-entry vector — exactly the operation in Fig. 1.2, just with complex entries and one extra rule (the result always has to land back on the unit-normalized state space, which is why gate matrices specifically have to be unitary — more on that in Ch. 4). The X gate is the "Swap" preset above, generalized to complex numbers. There's no new machinery between this chapter and that one — only new numbers.

Eigenvalues and eigenvectors

Look back at Fig. 1.2 for a second. For almost every choice of v, the matrix M knocks the vector off its original line — Mv points somewhere genuinely different from v. But for some special directions, M doesn't rotate the vector at all. It only stretches or shrinks it. Those special directions are called eigenvectors, and the stretch factor is the corresponding eigenvalue:

Mv = λv, v ≠ 0

In words: v is an eigenvector of M if applying M to v gives back the exact same direction, just scaled by the number λ.

Finding them

Rearranging Mv = λv gives (M − λI)v = 0. A nonzero v can only solve this if the matrix (M − λI) fails to be invertible — i.e. its determinant is zero. For a 2×2 matrix [[a,b],[c,d]], writing that out gives the characteristic equation:

$$\lambda^2 - (a+d)\lambda + (ad-bc) = 0$$

That's just a quadratic in λ — the coefficients are the matrix's trace (a+d) and determinant (ad−bc). Solve it with the quadratic formula and you have both eigenvalues.

Worked example. Take M = [[2,1],[1,2]]. Trace = 4, determinant = 3, so λ² − 4λ + 3 = 0, which factors as (λ−1)(λ−3) = 0: the eigenvalues are λ = 1 and λ = 3. Plugging λ = 3 back into (M − 3I)v = 0 gives [[−1,1],[1,−1]]v = 0, solved by v = (1, 1). Plugging in λ = 1 gives v = (1, −1). Check it yourself in the code cell below, or just watch Fig. 1.4 confirm it live.

Fig. 1.4 — eigenvectors of Fig. 1.2's current matrixedit the matrix above
The dashed lines are the eigenvector directions of whatever matrix you've set in Fig. 1.2 — change that matrix and these update instantly. Try the "Rotate 90°" preset: a pure rotation has no real eigenvector at all, which the panel will tell you directly.

Why this matters in quantum computing

This is not a side topic — it's arguably the single most-used piece of linear algebra in the entire subject. A few direct connections you'll meet by name later in this book:

  • Measurement outcomes are eigenvalues. An observable (a measurable quantity, like spin) is represented by a Hermitian matrix. The only values you can ever actually measure are that matrix's eigenvalues — Ch. 4 and Ch. 7 make this precise, and Ch. 4 explains exactly why Hermitian specifically guarantees those eigenvalues come out real, since a measurement outcome that was a complex number would be physically meaningless.
  • Eigenvectors are the states measurement collapses to. Measuring an observable forces the system into one of that observable's eigenvectors. The Pauli Z gate's eigenvectors are exactly |0⟩ and |1⟩ (eigenvalues +1 and −1); Pauli X's eigenvectors are |+⟩ and |−⟩. You already met all four states in Ch. 3 — you just hadn't met the word "eigenvector" yet.
  • Solving a quantum system means diagonalizing its Hamiltonian. The allowed energy levels of a quantum system are the eigenvalues of its Hamiltonian operator; the eigenvectors are the corresponding stable energy states. "Diagonalizing the Hamiltonian" — a phrase you'll see constantly in any quantum mechanics course — just means finding these.

Eigenvalues show up everywhere else, too

None of this machinery is quantum-specific — quantum mechanics just happens to be a field where eigenvalues are unavoidable. A few examples from elsewhere, each genuinely using the identical Mv = λv idea from this section:

  • Data science (PCA): the eigenvectors of a dataset's covariance matrix are its principal components — the directions of greatest variance; the eigenvalues tell you how much variance each direction explains.
  • Search engines: Google's original PageRank score is the dominant eigenvector of a giant matrix encoding which pages link to which.
  • Structural engineering: the eigenvalues of a structure's stiffness matrix are its natural resonant frequencies; the eigenvectors are the shapes it physically vibrates into at each one.
  • Markov chains: a system's long-run steady-state distribution is the eigenvector of its transition matrix with eigenvalue exactly 1.

Same equation, four unrelated fields. That's a fairly reliable sign you've found something fundamental rather than something specific to one subject.

Linear combinations and basis vectors

A linear combination is just a sum of scaled vectors: c₁v₁ + c₂v₂ + …. Two special vectors make this especially useful in 2 dimensions — the standard basis:

e₁ = [1, 0]ᵗ e₂ = [0, 1]ᵗ

Any 2-entry vector v = [v₁, v₂]ᵗ can be written as the linear combination v = v₁e₁ + v₂e₂ — the vector's own entries are exactly the coefficients needed to build it back out of the basis. Hold onto that sentence. In Ch. 3, e₁ and e₂ get renamed |0⟩ and |1⟩, and "v₁e₁ + v₂e₂" gets renamed "superposition." It's the identical fact, wearing different notation.

Fig. 1.3 — code, runs in your browser
Same numbers as Fig. 1.1 and 1.2 — edit and re-run to check your own examples against the widgets above.
Check your understanding

If a = (2, 1) and b = (−1, 3), what is a + b?

(1, 4) — add the components separately: (2 + −1, 1 + 3).

Check your understanding

Geometrically, what does multiplying a vector by a negative scalar do?

It reverses the vector's direction (in addition to scaling its length by the absolute value of the scalar).

Check your understanding

What is [[0,1],[1,0]] @ [3, 5]ᵗ?

[5, 3]ᵗ — this matrix swaps the two entries, exactly the real-number shadow of the X gate.

Check your understanding

Why is v = v₁e₁ + v₂e₂ called a "linear combination," and why does this matter later in the book?

It's a sum of basis vectors each scaled by a coefficient — exactly the definition of a linear combination. It matters because superposition (Ch. 3) is this exact same structure, with e₁/e₂ renamed |0⟩/|1⟩ and the coefficients renamed probability amplitudes.

Check your understanding

What's the one rule that quantum gate matrices have to satisfy that an arbitrary 2×2 matrix in Fig. 1.2 doesn't?

The matrix has to be unitary — it has to send every valid (normalized) state to another valid (normalized) state. Fig. 1.2's "Shear" preset, for example, is not unitary and would never appear as a real quantum gate. Ch. 4 covers exactly what unitary means and why it's required.

Check your understanding

For M = [[2,1],[1,2]], confirm that v = (1,1) is an eigenvector, and find its eigenvalue.

Mv = (2·1+1·1, 1·1+2·1) = (3,3) = 3·(1,1) — same direction as v, scaled by 3. So λ = 3.

Check your understanding

Why must quantum observables specifically be Hermitian matrices, rather than just any matrix?

Because measurement outcomes are the matrix's eigenvalues, and a measured quantity has to be a real number. Hermitian matrices are exactly the ones guaranteed to have real eigenvalues — an arbitrary matrix could have complex ones, which wouldn't correspond to anything physically measurable.

Review queue

Scroll back to a chapter's quiz cards to review them once they're due — a full cross-chapter queue view is a planned upgrade.