← Quantum Store · Guides · Lessons · Glossary · About · Türkçe

Preparation course: maths for quantum computing · Lesson 5 / 7 · 10 min

Matrices: every gate is a table

Every quantum gate is a table of numbers (a matrix), and applying a gate means multiplying the state vector by that table. Meet the X, Z and H matrices and see why the order of gates matters.

Multiplying a matrix by a vector

A matrix is a table of numbers in rows and columns. Single-qubit gates are matrices with 2 rows and 2 columns. To multiply a matrix by the vector (a, b), take each row in turn, multiply its numbers with the matching numbers of the vector and add them up.

The rows of the X gate are (0 1) and (1 0). The first row gives 0·a + 1·b = b, the second 1·a + 0·b = a, so the result is (b, a). X swaps the two amplitudes: (1, 0), that is |0⟩, becomes (0, 1), that is |1⟩. That is exactly the NOT operation.

The Z and H matrices

The rows of Z are (1 0) and (0 −1): it turns (a, b) into (a, −b). It flips the sign of the amplitude of |1⟩ and leaves the probabilities alone.

The rows of H are (1 1) and (1 −1), all multiplied by 1/√2. H turns (1, 0) into (0.707, 0.707): an equal superposition. It turns (0, 1) into (0.707, −0.707): the same probabilities with a negative amplitude. That is where the negative amplitude of the previous lessons comes from.

Applying gates one after another

A circuit is a series of matrices multiplying the vector in turn. Apply H to (0.707, 0.707) once more and the first row gives (0.707 + 0.707)/√2 = 1, the second (0.707 − 0.707)/√2 = 0: you are back at |0⟩. Two H gates act as if nothing happened.

Order matters. X followed by H gives (0.707, −0.707); H followed by X gives (0.707, 0.707). Unlike multiplying ordinary numbers, swapping the order of a matrix product can change the result.

Try it yourself

Delete the two gates of the negative amplitude example and add them back in the other order: H first, then X. The state vector is now (0.707, 0.707): the minus sign is gone. Changing the order changed the result.

Open the circuit in your browser

The circuit playground is in Turkish. Button guide: “1000 kez ölç” = measure 1000 times, “Durum vektörünü göster” = show the state vector, “Bu devrenin Qiskit kodu” = this circuit’s Qiskit code, “Geri al” = undo, “Temizle” = clear. Click a gate in the circuit to remove it.

Key points

Test yourself

The rows of the Z matrix are (1 0) and (0 −1). What does Z turn the vector (a, b) into?

Show the answer

(a, −b). The first row gives 1·a + 0·b = a, the second 0·a − 1·b = −b. Z only flips the sign of the amplitude of |1⟩.

← Complex numbers: meet i · The tensor product: putting qubits together →

Share: X · LinkedIn