BACK TO JUST ENOUGH MATH
03.03/LESSON
BEGINNER10 MIN READ

MATRICES AS MACHINES THAT TRANSFORM VECTORS

Matrix-vector multiplication, worked step by step, and your first look at a gate before it has a name.

We now have vectors (Lesson 1) to represent qubit states, and complex numbers (Lesson 2) to fill their entries. But states just sitting there aren't very interesting — computation is about transforming things. In Module 1, we described a quantum gate loosely as "a rotation you can perform on the Bloch sphere." Now we need the precise mathematical object that performs that rotation on our vector. That object is a matrix.


What a Matrix Is

Matrix

A matrix is a rectangular grid of numbers. For this entire course, we will almost exclusively use 2x2 matrices (2 rows, 2 columns) to describe single-qubit operations, since our qubit vectors have exactly 2 entries. A general 2x2 matrix looks like:

where a, b, c, d can be any numbers, including complex numbers.

The Core Idea: A Matrix as a Machine

Think of a matrix the way you'd think of a pure function in code: it's a machine that takes a vector as input and produces a new vector as output, with no side effects and no randomness — the same input vector always produces the same output vector. This "machine" metaphor is exactly why Module 4 will describe every quantum gate as "a matrix that transforms the state vector."

Matrix-Vector Multiplication, Step by Step

Here is the rule for multiplying a 2x2 matrix by a 2-entry column vector:

In words: to get the top entry of the result, multiply the matrix's top row by the vector, entry by entry, and add the products. To get the bottom entry, do the same with the matrix's bottom row.


Worked Example 1: The Identity Matrix

The simplest possible matrix is called the identity matrix, which does nothing at all to a vector — the "do nothing" machine:

Applying it to a general vector :

Exactly the same vector came out as went in — confirming this matrix truly "does nothing."

Worked Example 2: A Matrix That Swaps the Two Entries

Consider the matrix:

Applying it to :

This matrix turned |0⟩ into |1⟩. Let's check the reverse — apply it to |1⟩:

This matrix flips |0⟩ and |1⟩ into each other — a perfect quantum analogue of a classical NOT gate. This exact matrix is what Module 4, Lesson 2 will formally introduce as the Pauli-X gate. We're not studying gates yet — this is purely a matrix arithmetic exercise — but it's worth flagging so the payoff feels earned when you reach it.

Worked Example 3: A Matrix Applied to a Superposition Vector

Let's apply the same "swap" matrix to the superposition-shaped vector we built in Lesson 1: .

The output is identical to the input. This isn't a coincidence — it's a preview of eigenvectors, which get their own full treatment in Lesson 6.


Composing Matrices: Applying One After Another

What if we want to apply one matrix, then another? This corresponds to matrix multiplication, essential once we build multi-step quantum circuits (Module 4, Lesson 7). The rule for multiplying two 2x2 matrices:

Worked Example: Multiplying the Swap Matrix by Itself

Applying the "swap" matrix twice gets you back to the identity matrix — which makes complete sense: swapping |0⟩ and |1⟩, then swapping them again, returns everything to where it started. This "do it twice, get nothing" property will reappear as an important property of several real gates in Module 4.

ORDER MATTERS

Unlike ordinary number multiplication, matrix multiplication is generally not commutative -- that is, AB is usually not the same as BA. This will matter a great deal once we build multi-gate circuits in Module 4, Lesson 7: the order in which you apply gates changes the outcome, exactly the way the order of operations matters in a sequential program.


Practice Questions

Test your understanding


KEY TAKEAWAYS

Remember these points

A matrix is a grid of numbers that acts as a "machine," transforming an input vector into an output vector via matrix-vector multiplication

The identity matrix leaves every vector unchanged -- the "do nothing" operation

Matrices can be multiplied together to represent applying one transformation after another -- but unlike ordinary numbers, the order generally matters (AB does not equal BA)

A specific matrix with rows [0,1] and [1,0] swaps the entries of a vector and turns |0⟩ into |1⟩ and vice versa -- this is the exact matrix Module 4 will formally name the Pauli-X gate

Every quantum gate you will meet starting in Module 4 is, mathematically, nothing more than a specific 2x2 (or larger) matrix applied to a state vector